Non-zero column value

1 view (last 30 days)
Tha saliem
Tha saliem on 8 Jun 2017
Commented: Tha saliem on 9 Jun 2017
hi if have a matrix like this:
In this matrix i want to check that apart from diagonal values(1,1 & 2,2 etc.), if there are some other non-zero elements in the row then display that row's index. In A, it should display 2 and 4.
Thanks in advance.

Accepted Answer

Image Analyst
Image Analyst on 8 Jun 2017
Try eye(), any(), and find():
diagonalElements = logical(eye(length(A)))
% Make copy of A so we don't change
% the original A (which could be bad).
Acopy = A;
% Set diagonal elements = 0.
Acopy(diagonalElements) = 0
rowsWith1s = find(any(Acopy, 2))
Tha saliem
Tha saliem on 9 Jun 2017
Yes got it. Thanks alot for helping.

Sign in to comment.

More Answers (0)


Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!