finding coordinates or locations in matrix?

23 ビュー (過去 30 日間)
Elin
Elin 2011 年 5 月 4 日
コメント済み: Sara 2020 年 11 月 16 日
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
>>

採用された回答

Matt Tearle
Matt Tearle 2011 年 5 月 4 日
[row,col] = find(...)
  4 件のコメント
Image Analyst
Image Analyst 2020 年 9 月 11 日
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 2020 年 11 月 16 日
Hi, how to find the coordnates for 3D meshgrid as following
x = linspace(-10,10,50);
[X,Y,Z]=meshgrid(x,x,x);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by