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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by