How to input a matrix as input into a function

4 ビュー (過去 30 日間)
William Brown
William Brown 2018 年 2 月 26 日
回答済み: BhaTTa 2024 年 10 月 18 日
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!

回答 (1 件)

BhaTTa
BhaTTa 2024 年 10 月 18 日
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.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by