write a MATLAB function that takes two matrices A and B as i
write a MATLAB function that takes two matrices A and B as input and returns A * B if A and B are conformable, and returns the empty matrix [] otherwise; You may not use the built in * operator for matrices – only scalars, so you will need to use the definition of matrix multiplication and one loop (column) nested in another loop (row), then either a third nested loop ( k ) or try to use dot() and transposition
Solution
function M=matrixmul(A,B)
x=size(A);
y=size(B);
M=zeros(x(1),y(2));
if(x(2)==y(1))
for i = 1 : x(1)
for j = 1 : y(2)
theSum = 0;
for k = 1 : x(2)
theSum = theSum + A(i, k) * B(k, j);
end
M(i, j) = theSum;
end
end
else
M=[];
end
![write a MATLAB function that takes two matrices A and B as input and returns A * B if A and B are conformable, and returns the empty matrix [] otherwise; You ma write a MATLAB function that takes two matrices A and B as input and returns A * B if A and B are conformable, and returns the empty matrix [] otherwise; You ma](/WebImages/21/write-a-matlab-function-that-takes-two-matrices-a-and-b-as-i-1046823-1761544616-0.webp)