Checking if a matrix is symmetric
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abdulelah Jo
am 26 Nov. 2018
Kommentiert: Abdulelah Jo
am 26 Nov. 2018
Hi
i want to check if the matrix is symmetric or not by using nested loops and display a certain message if it is or not. the problem is that it's displaying the message after comparing each element of the original matrix with the ones in the transposed or inversed matrix.. i want the message to be displayed after both matrices are compared!.
A = [ 2 6 9; 7 3 8; 10 11 12];
for i = 1:3
for j = 1:3
if(A(i,j) == A(j,i))
disp('true')
else
disp('false')
end
end
end
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 26 Nov. 2018
disp(isequal(A,A.'))
9 Kommentare
Walter Roberson
am 26 Nov. 2018
A = [ 2 6 9; 7 3 8; 10 11 12];
for i = 1 : 1
for j = 1 : 1
fprintf(['The matrix is a' repmat('\b',isequal(A,A.')) 'symmetric!\n']);
end
end
Weitere Antworten (0)
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!