How to input a matrix as input into a function
4 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!