Finding the nonzero element in a specific row

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 ?

답변 (2개)

infinity
infinity 2019년 7월 18일
편집: infinity 2019년 7월 18일

0 개 추천

Hello,
Yes, there is. You can refer this simple example
A = [1 2; 0 3]
[rows,cols,vals] = find(A==0)

댓글 수: 2

Thank you is there a simple way to make it such that
i determine which row to find
for example in your example
i want to type the row number and it gives me the index(2,2) for the non zero element
hope this clears things up
infinity
infinity 2019년 7월 18일
Hello,
You could see the answer below of @Star

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

Star Strider
Star Strider 2019년 7월 18일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2019년 7월 18일

댓글:

2019년 7월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by