フィルターのクリア

How can I threshold a matrix and get the coordinates of those values?

7 ビュー (過去 30 日間)
Native
Native 2018 年 12 月 10 日
編集済み: Guillaume 2018 年 12 月 10 日
I have a matrix, X with dimensions 132X132, with values ranging from -0.1 to 0.4. I'd like to threshold it to values above 0.2, and most importantly, obtain the coordinates to which those values belonged to in the previous matrix.
Thank you.

回答 (1 件)

MUHAMMED IRFAN
MUHAMMED IRFAN 2018 年 12 月 10 日
編集済み: MUHAMMED IRFAN 2018 年 12 月 10 日
ind = find(X>.2);
This gives the index of all the points in X greater than 0.2 using linear indexing.
To convert the single indices to subscripts,
[I,J] = ind2sub([132,132],ind);
This gives x and y coordinates of all points with values greater than 0.2
To get the values of all those points,Go
myPoints = X(find(X>0.2));
  2 件のコメント
Stephen23
Stephen23 2018 年 12 月 10 日
Note that indexing with one index is called linear indexing in the MATLAB documentation:
Guillaume
Guillaume 2018 年 12 月 10 日
編集済み: Guillaume 2018 年 12 月 10 日
If you want 2D coordinates out of find just ask for them rather than getting linear indices and converting them into 2d indices:
[row, column] = find(X > 0.2); %no need for ind = find(X>0.2) followed by [row, column] = ind2sub(...)
Similarly, find can also give you the values. It's the third output:
[row, column, value] = find(X > 0.2); %much faster than X(find(X>0.2))
Also, note that as a filter, find is never needed. You can use the logical array input directly as a filter, so:
X(find(X > 0.2))
is a waste of time,
X(X > 0.2)
is faster and simpler.
Finally, it's never a good idea to hardcode the size of the matrices. If you had to use ind2sub,
[row, column] = ind2sub(size(X), ind); %instead of ind2sub([132 132], ind)
would be a lot safer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by