Finding the nonzero element in a specific row

6 views (last 30 days)
If i have a matrix and i want to find the indices of a non zero elements in a specific row only how can i do that ?

Answers (2)

infinity
infinity on 18 Jul 2019
Edited: infinity on 18 Jul 2019
Hello,
Yes, there is. You can refer this simple example
A = [1 2; 0 3]
[rows,cols,vals] = find(A==0)
  2 Comments
infinity
infinity on 18 Jul 2019
Hello,
You could see the answer below of @Star

Sign in to comment.


Star Strider
Star Strider on 18 Jul 2019
Select the row, then use find:
A = [1 3 0; 2 0 4; 0 7 9]
DesiredRow = 2
cix = find(A(DesiredRow,:) ~= 0)
so:
A =
1 3 0
2 0 4
0 7 9
DesiredRow =
2
cix =
1 3

Categories

Find more on Loops and Conditional Statements 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!