Function for user to define any nxn matrix.
古いコメントを表示
Hey gang,
For uni I need to create a function script that will allow a user to take any 2 nxn matrices and multiply them together.
I realise matlab can do this anyway but the exercise is to understand some of how matlab works.
My issue is that I don't actually know how to set it up so that my matrix will absorb any values put into it. From there I reckon I can do the assignment.
Any help would be just fab. Sorry if my request seems abit confusing, I can't think of how to word what I want very well.
Thanks!
回答 (1 件)
KALYAN ACHARJYA
2019 年 2 月 16 日
編集済み: KALYAN ACHARJYA
2019 年 2 月 16 日
function mul_result=mul1(mat1,mat2)
mul_result=mat1*mat2;
end
Here mat1,mat2 can have any order of matrices,but please note that they must matrix multiplicable.
Save it (mul1.m) in your current working directory and call the function using mul1 from command or other scripts
See the Example, Command Window
>> A=randi(3,4)
A =
3 2 3 3
3 1 3 2
1 1 1 3
3 2 3 1
>> B=randi(3,4)
B =
2 2 3 2
3 1 3 1
3 3 3 3
3 3 2 1
>> C=mul1(A,B)
C =
30 26 30 20
24 22 25 18
17 15 15 9
24 20 26 18
>>
カテゴリ
ヘルプ センター および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!