How to calculate multiplying two matrices using (for) and (if) loops together ???
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
hcourah same
am 14 Dez. 2018
Kommentiert: Walter Roberson
am 20 Dez. 2018
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 Kommentare
Image Analyst
am 15 Dez. 2018
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.
Akzeptierte Antwort
Image Analyst
am 15 Dez. 2018
Hint:
if ~isequal(R, G)
uiwait(errordlg('The matrices are not the same size'));
return;
end
0 Kommentare
Weitere Antworten (1)
Omer Yasin Birey
am 15 Dez. 2018
Bearbeitet: Omer Yasin Birey
am 15 Dez. 2018
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!