Converting a matrix of points to a list of x & y coordinates
Show older comments
Hello,
I have a matrix of size n*n, filled with zeros. Some points are filled with A's. I'd like to take this matrix and turn it into two arrays, one with the x-coordinates of each A and the other with the y-coordinates of each A.
I have seen numerous ways of going the other way, i.e. from a list of coordinates to a matrix, but none going this way.
Any help is greatly appreciated!
Accepted Answer
More Answers (2)
Iain
on 18 Aug 2014
Index_of_As = find( matrix );
[down along] = ind2sub(size(matrix),Index_of_As);
ind1d = find( myMatrix == 'A' );
[y, x] = ind2sub( [n n], ind1d );
should be close to doing the job, although it depends what you mean by 'A'. Do you have a cell array? The above code would work if, instead of 'A', you had some numerical value, but otherwise it would likely need a bit of syntactical modification depending if you have a cell array.
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!