finding coordinates or locations in matrix?

30 visualizzazioni (ultimi 30 giorni)
Elin
Elin il 4 Mag 2011
Commentato: Sara il 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
>>

Risposta accettata

Matt Tearle
Matt Tearle il 4 Mag 2011
[row,col] = find(...)
  4 Commenti
Image Analyst
Image Analyst il 11 Set 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 il 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);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by