Borrar filtros
Borrar filtros

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

8 visualizaciones (últimos 30 días)
Native
Native el 10 de Dic. de 2018
Editada: Guillaume el 10 de Dic. de 2018
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.

Respuestas (1)

MUHAMMED IRFAN
MUHAMMED IRFAN el 10 de Dic. de 2018
Editada: MUHAMMED IRFAN el 10 de Dic. de 2018
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 comentarios
Stephen23
Stephen23 el 10 de Dic. de 2018
Note that indexing with one index is called linear indexing in the MATLAB documentation:
Guillaume
Guillaume el 10 de Dic. de 2018
Editada: Guillaume el 10 de Dic. de 2018
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by