I find the answer myself.
Refer to this file on Mathworks file exchange.
It calls for a lot of nasty tricky calculations and transformations. Courtesy to Benoît Valley
First, get config of the figure,
% get axes properties
funit=get(get(h_axes,'Parent'),'Units');
% get axes properties
aunit=get(h_axes,'Units');
darm=get(h_axes,'DataAspectRatioMode');
pbarm=get(h_axes,'PlotBoxAspectRatioMode');
dar=get(h_axes,'DataAspectRatio');
pbar=get(h_axes,'PlotBoxAspectRatio');
xlm=get(h_axes,'XLimMode');
ylm=get(h_axes,'YLimMode');
xd=get(h_axes,'XDir');
yd=get(h_axes,'YDir');
% set the right units for h_axes
set(h_axes,'Units',funit);
axesoffsets = get(h_axes,'Position');
x_axislimits = get(h_axes, 'xlim'); %get axes extremeties.
y_axislimits = get(h_axes, 'ylim'); %get axes extremeties.
x_axislength = x_axislimits(2) - x_axislimits(1); %get axes length
y_axislength = y_axislimits(2) - y_axislimits(1); %get axes length
and finally
xfigure = xab+xwb*(xaxes-x_axislimits(1))/x_axislength;
Why I don't use generate code?
Generate code
gives me this sort of stuff:
% Create line
annotation(figure1,'line',[0.223214285714286 0.694642857142857],...
[0.552380952380952 0.630952380952381]);
Which is not related to existing lines, points or figures, not to mention the variables not plotted. So basically I'm looking for ways to get those point positions in that annotation
coordinates, which is dealt with in the above code.
If I didn't get you guys right on how to use generate code
, plz let me know.