Binary matrix to array of poitns

1 回表示 (過去 30 日間)
Crandel
Crandel 2016 年 5 月 4 日
編集済み: Stephen23 2016 年 5 月 4 日
Hi, I have a binary image (only 0 and 1) and I want to convert it to x-y arrays.
For example:
Matrix
0 1 0 1
0 0 0 1
1 0 0 0
0 0 0 0
Obtain:
x = [1 1 2 3];
y = [2 4 4 1];
I can do it with two loops, but I'm finding something more fast. Thanks

採用された回答

Stephen23
Stephen23 2016 年 5 月 4 日
編集済み: Stephen23 2016 年 5 月 4 日
>> [y,x] = find(M.')
y =
2
4
4
1
x =
1
1
2
3

その他の回答 (1 件)

CS Researcher
CS Researcher 2016 年 5 月 4 日
Do the x and y arrays have to be in that order? If not, you can do this:
[x,y] = find(A>0);

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by