필터 지우기
필터 지우기

Multiplying 2 Matrices A and B from Scratch (not built in function

조회 수: 14 (최근 30일)
Abdalla Khan
Abdalla Khan 2019년 6월 16일
댓글: madhan ravi 2019년 6월 17일
How can i write a matlab function which accepts two Matrices A and B and from scratch(indexing - not built in functions) multiplies them together. in the case that they can not be multiplied together simply return an empty matrix ([])
  댓글 수: 1
dpb
dpb 2019년 6월 16일
Obviously homework...show your work to date and where, specifically, you got stuck on a Matlab-related question.
Of course, you start with the definition of what matrix multiplication is...

댓글을 달려면 로그인하십시오.

답변 (1개)

Manvi Goel
Manvi Goel 2019년 6월 17일
Here you go
function result = mult(a, b)
[r1, c1] = size(a);
[r2, c2] = size(b);
if( c1 == r2)
result = zeros(r1, c2);
for i = 1: r1
for j =1:c2
for k = 1:r2
result(i,j) = result(i,j) + a(i,k) * b(k,j);
end
end
end
else
result = [];
end
disp(result)
end
  댓글 수: 1
madhan ravi
madhan ravi 2019년 6월 17일
Providing a complete solution to a homework problem is totally not recommended in this forum.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by