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!