How to get the y values between two x values on a plot-MATLAB

1k Views Asked by At

I have a plot (it is a spectra). I want to choose some peaks for fitting. How can I select a region from the Matlab plot? I want to choose some regions and do exponential fit. If I can extract the x and y values in those regions, I can fit the curves.

PS: I already have a program which calls the data and plot the spectra. As this program is written by someone else, I am not able to find where the x and y values are stored. It seems a bit complicated program. I just want to keep the same program and add some more lines or functions so that I can do my job (fitting the curve for some selected peaks)...

1

There are 1 best solutions below

0
On

You can get data directly from MATLAB figure using get function. See the following example:

x = -10:0.1:10;
y = (x/5).^2+rand(size(x));
plot(x,y)
ch = get(gca,'child');
xdata = get(ch,'xdata');
ydata = get(ch,'ydata');
ydata(abs(xdata)>2)=[];
xdata(abs(xdata)>2)=[];
hold on
plot(xdata,ydata,'r')