find function does not output values

조회 수: 5 (최근 30일)
Alex
Alex 2014년 12월 17일
댓글: Alex 2014년 12월 17일
I am using the find function. I have an 1196x1600 array called 'test' with some values zero and others nonzero. I use the following command to get the indices and values:
[rows,cols,vals]=find(test~=0);
the rows and cols vectors work well, but the vals vector just outputs logical array with a 1 in every cell. The doc for find says that this will output the values associated with the indices but it is not doing that. Please help.

채택된 답변

Guillaume
Guillaume 2014년 12월 17일
편집: Guillaume 2014년 12월 17일
"this will output the values associated with the indices but it is not doing that".
Yes, it is. The matrix that you pass to find is not the test matrix but:
test ~= 0
which is a logical array. Hence its values are either 0 (false) or 1 (true).
It's very simple to fix in your case:
[rows, cols, vals] = find(test);
  댓글 수: 1
Alex
Alex 2014년 12월 17일
Thanks! I feel dumb. It says right in the doc for 'find' that it returns the nonzero entries. Oh well...now I know.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by