필터 지우기
필터 지우기

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

조회 수: 8 (최근 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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by