How to calculate multiplying two matrices using (for) and (if) loops together ???

조회 수: 2 (최근 30일)
How to calculate multiplying two matrices provided that the number of line elements in the first matrix equals the number of column elements in the second matrix (using the loop (for) and (if) together) thank you
  댓글 수: 3
Image Analyst
Image Analyst 2018년 12월 15일
I think you got the requirement wrong: "the number of line elements in the first matrix equals the number of column elements in the second matrix"
It should be, with r1xc1 * r2xc2, then c1 must equal r2 - the number of columns of the first matrix must equal the number of rows in the second matrix, not what you said. You'll see MATLAB using jargon like "the inner dimensions must match" meaning c1 = r2.
Anyway, see hints below in the Answers section.
Walter Roberson
Walter Roberson 2018년 12월 20일
please do not close questions that have an answer

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

채택된 답변

Image Analyst
Image Analyst 2018년 12월 15일
Hint:
if ~isequal(R, G)
uiwait(errordlg('The matrices are not the same size'));
return;
end

추가 답변 (1개)

Omer Yasin Birey
Omer Yasin Birey 2018년 12월 15일
편집: Omer Yasin Birey 2018년 12월 15일
Hi hcourah, you can add try - catch to send the message
for i=1:n
for j=1:m
try
c(i,j)=A(i,:)*b(:,j);
catch
warning('The matrices are not the same dimension.')
end
end
end

카테고리

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