MATLAB: Getting the data point from two plotted curves in one figure

data acquisitionplot

Hi all, I am using Matlab R2017b that runs on Windows Server 2012 R2.
I have two curves on the a single figure and I want to export the data point of theses curves to different variables and save them later for further manipulation.
When I run the following code:
h = findobj(gca,'Type','line')
x=get(h,'Xdata')
y=get(h,'Ydata')
I get the data points of imag(neff).
My problem is that I want to get the y point of the second curve real(neff). How can I get the data points of real(neff) into a separate variable?

Best Answer

h = findobj(gca, 'Type', 'line');
x1 = get(h(1), 'XData')
y1 = get(h(1), 'YData')
x2 = get(h(2), 'XData')
y2 = get(h(2), 'YData')
But actually your code should work already. If h contains 2 line handles (does it?), then
h = findobj(gca, 'Type', 'line');
x = get(h, 'XData')
replies a {2 x 1} cell. Now x{1} contains the XData of the first line, x{2} of the 2nd line - and the same for the YData. Therefore I cannot reconsider why you state, that you "get the data points of imag(neff)" only. Why do you think that this is the fact?
[EDITED] Ah, this is not one axes object, but two created by plotyy or yyaxis. Then you do not need gca only, but all line objects:
h = findobj(gcf, 'Type', 'line')
You have to search in the current figure, not in the active axes only. Then your code will work.
By the way: Did you use the debugger to check, what your "h = findobj(gca,'Type','line')" replies?