If I understand correctly, these are the two things you want to know:
- You have a figure containing a plot of some arbitrary 2d line, whose
x_vec, y_vec
are unknown to you and you want to extract them from the figure\axes.
- You want to get the
xtick
and ytick
positions used in the figure you have.
The reason your code does not work, is because you're trying to access a property of the axes
, whereas what you want to access is the property of the line
(i.e. the curve in the plot).
To solve your first problem, you can resort to the following methods:
Manual: using the edit plot
figure tool you can get to the XData
and YData
properties of the line, in the following manner:
Programmatic: you need to find the handle
(i.e. pointer) to the line, and then use your code on that handle (and not on gca
):
%// If there's only one entity (child) in the axes:
hLine = get(gca,'Children');
%// If there's more than one child:
hChildren = findobj(gca,'Type','line');
hLine = hChildren(1); %// Or any other logic you need to pick the correct line
%// Then comes your code:
xD = get(hLine,'XData'); yD = get(hLine,'YData');
For the second problem you can use gca
to get XTick
and YTick
:
xT = get(gca,'XTick'); yT = get(gca,'YTick');
To get the step size I'd suggest simply using diff()
.