MATLAB: How to get all the data points from a 10×10 figure

MATLABpoint

Hi,
I've ploted a 10×10 square. Now i would like to get all the x and y data points in this 10×10 figure. I would like to apply a for loop to get all the points. Can anybody help me ?? Thanks in advance .

Best Answer

[Edit]: You likely already have the points since you just plotted them (as Image Analyst pointed out). However, if you just have the figure and you do not have the code that produced the figure, here's a soltuion below.
You can get the x and y coordinates from your axis like this:
ah = gca; %handle to axis
XData = [ah.Children.XData];
YData = [ah.Children.YData];
XData and YData are vectors.
There's no need for a for-loop. However, if you choose to use one (which is unnecessary),
chil = ah.Children;
XData = cell(size(chil));
YData = cell(size(chil));
for i = 1:length(chil)
XData{i} = chil(i).XData;
YData{i} = chil(i).YData;
end
which stores (x,y) coordinates for each child in a cell array. You could, of course, orgnaize that differently depending on your needs.
Related Question