How can I make a function where I ask two input matrices from user and do matrix multiplication using If-else conditions and error functions?
5 ビュー (過去 30 日間)
古いコメントを表示
I'm new at matlab and I still don't know how this problem actually works. And I still don't know how to ask input from user at the first place. Can you help me please?
1 件のコメント
David Hill
2020 年 9 月 16 日
Look at input() function
a=input('enter matrix a: for example [1,5,9;2,4,6] ');
回答 (1 件)
Samiu Haque
2020 年 9 月 16 日
編集済み: Samiu Haque
2020 年 9 月 16 日
fprintf('For matrix input use the standard format\n e.g. [1 2 3;4 5 6]\n')
a = input('Enter first matrix: ');
b = input('Enter second matrix: ');
[m,n]=size(a);
[p,q]=size(b);
if n~=p
disp('Error')
return
end
Result = a*b
Use this template. I think this might help
3 件のコメント
Samiu Haque
2020 年 9 月 16 日
If the dimension is okay, then it should work. There might have some issue, regarding the input method.
For example:
1x3 matrix should be written as [1 2 3]
and 3x2 matrix should be written as [4 5;6 7;8 9]
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!