finding coordinates or locations in matrix?

141 views (last 30 days)
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
>>

Accepted Answer

Matt Tearle
Matt Tearle on 4 May 2011
[row,col] = find(...)
  4 Comments
Image Analyst
Image Analyst on 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 on 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);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!