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!