finding coordinates or locations in matrix?
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Elin
el 4 de Mayo de 2011
Comentada: Sara
el 16 de Nov. de 2020
Hi, I am trying to find a way of extracting the coordinates of the values that are larger than 20 in a magic(5) matrix.
I would like to have the coordinates specified as 3,5 instead of 15 and so on,, is that possible?
Thanks
>> r=magic(5)
r =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> b=r>20
b =
0 1 0 0 0
1 0 0 0 0
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
>> find(b==1)
ans =
2
6
15
19
23
>>
0 comentarios
Respuesta aceptada
Matt Tearle
el 4 de Mayo de 2011
[row,col] = find(...)
4 comentarios
Image Analyst
el 11 de Sept. de 2020
Not what anyone else gets:
X = zeros(6, 6);
X(6, 1) = 1;
X(1, 6) = 1
[row, col] = find(X == 1)
[row, col] = find(X > 0)
The result is not an error. It is:
X =
0 0 0 0 0 1
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
1 0 0 0 0 0
row =
6
1
col =
1
6
row =
6
1
col =
1
6
Sara
el 16 de Nov. de 2020
Hi, how to find the coordnates for 3D meshgrid as following
x = linspace(-10,10,50);
[X,Y,Z]=meshgrid(x,x,x);
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!