MATLAB: Binary matrix to array of poitns

matrix image array convert

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

Best Answer

>> [y,x] = find(M.')
y =
2
4
4
1
x =
1
1
2
3