finding coordinates or locations in matrix?

30 vues (au cours des 30 derniers jours)
Elin
Elin le 4 Mai 2011
Commenté : Sara le 16 Nov 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
>>

Réponse acceptée

Matt Tearle
Matt Tearle le 4 Mai 2011
[row,col] = find(...)
  4 commentaires
Image Analyst
Image Analyst le 11 Sep 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
Sara le 16 Nov 2020
Hi, how to find the coordnates for 3D meshgrid as following
x = linspace(-10,10,50);
[X,Y,Z]=meshgrid(x,x,x);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by