How to program a function in MATLAB that takes two matrices A and B as input and outputs the product matrix A*B?

Viewed 23

Question: How do I program a function that takes two matrices A and B as input and outputs the product matrix A*B? Using MATLAB, with stuff like "for" or "while", i.e., loops or conditionals.

Attempt:

function prodAB=MultiplicoMatrices(A,B)

prod=0;

prodAB=[];

for i=1:length(A)

    for j=1:length(B)

        prod=prod+A(i,j)*B(j,i);

    end

    prodAB(i,j)=prod;

    prod=0;

end

A =

     1     2
     3     4

 B=[5 6 ; 7 8]

B =

     5     6
     7     8
>> prodAB=MultiplicoMatrices([1 2; 3 4],[5 6; 7 8])

prodAB =

     0    19
     0    50
0 Answers
Related