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)...

  • $\begingroup$ I am unsure how your data is stored, but you could use something like find(spectra>value_min&spectra<value_max) to get the corresponding indexes. $\endgroup$
    – zuggg
    Jul 15 '13 at 12:09
  • $\begingroup$ If you cannot modify the code or identify x and y data in it, you can work with the image file itself. If there are not too many peaks, you can measure their pixel coordinates just by hovering over them in Paint, and then rescale to proper units. (Sounds stupid, but why not...) $\endgroup$
    – 40 votes
    Jul 15 '13 at 17:26
  • $\begingroup$ This is not a question about mathematics.... $\endgroup$ Jul 16 '13 at 14:04
  • $\begingroup$ Matlab and other computing problems which are mathematical in nature are welcome here, but in general questions about the physical use of the software are discouraged... $\endgroup$
    – user1729
    Jul 16 '13 at 14:22

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));
ch = get(gca,'child');
xdata = get(ch,'xdata');
ydata = get(ch,'ydata');
hold on

Not the answer you're looking for? Browse other questions tagged or ask your own question.