How to input a matrix as input into a function

4 vues (au cours des 30 derniers jours)
William Brown
William Brown le 26 Fév 2018
Réponse apportée : BhaTTa le 18 Oct 2024
I'm trying to input a matrix as my input into the function I'm making. When inputting the matrix in the command window when calling the script, I get the error unexpected matlab expression. I'm not sure of the syntax to input a matrix in or if it is even possible to in the first place.
Here is my code below if that helps at all:
function determinantOutput =myDeterminantCalc(a)
if size(a)==3
determinantOutput= a(1,1) * (a(2,2) * a(3,3) - a(3,2)
* a(2,3))- a(1,2) * (a(2,1) * a(3,3) - a(3,1) * a(2,3)) + a(1,3)
* (a(2,1) * a(3,2) - a(3,1) * a(2,2));
else
determinantOutput= (a(1,1)* a(2,2) - a(1,2)*a(2,1));
end
I'm pretty new to MATLAB any help is greatly appreciated, thanks!

Réponses (1)

BhaTTa
BhaTTa le 18 Oct 2024
Hey @William Brown, you can pass a matrix as an argument to the function, while calling the function from command line make sure you would call it as below:
>>myDeterminantCalc([1 2; 3 4])
Hope it helps.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by