Checking if a matrix is symmetric

조회 수: 19 (최근 30일)
Abdulelah  Jo
Abdulelah Jo 2018년 11월 26일
댓글: Abdulelah Jo 2018년 11월 26일
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

채택된 답변

Bruno Luong
Bruno Luong 2018년 11월 26일
disp(isequal(A,A.'))
  댓글 수: 9
Walter Roberson
Walter Roberson 2018년 11월 26일
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
Abdulelah  Jo
Abdulelah Jo 2018년 11월 26일
Thanks alot! it worked <3

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

추가 답변 (0개)

카테고리

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