Binary matrix to array of poitns

1 Ansicht (letzte 30 Tage)
Crandel
Crandel am 4 Mai 2016
Bearbeitet: Stephen23 am 4 Mai 2016
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

Akzeptierte Antwort

Stephen23
Stephen23 am 4 Mai 2016
Bearbeitet: Stephen23 am 4 Mai 2016
>> [y,x] = find(M.')
y =
2
4
4
1
x =
1
1
2
3

Weitere Antworten (1)

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

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by