Page 1 of 1

fitting two spectra with esfit

Posted: Mon Mar 06, 2023 5:15 am
by Patto

Hi,
I've been trying to fit two spectra for one sample at different frequencies using X band and Q band. I tried previous posts (viewtopic.php?p=1743&hilit=globalfit#p1743 viewtopic.php?p=3166&hilit=scale#p3166). ButI always run into the error "First input parameter must be a valid function name or function handle." Does anybody share me an example to do this. THX


Re: fitting two spectra with esfit

Posted: Mon Mar 06, 2023 12:21 pm
by EricWalter

What version of Matlab are you using? I had problems with functions defined inside a script with older versions (I just made the function a separate .m file). But beyond that, it looks like you will overwrite your x-band data with your Q-band, I think you need to cat them together. And I think you need to scale each simulation to the experimental data separately.

I got your script to run in version 6 with matlab 2018 by replacing line 53 with the new syntax for esfit:
esfit(spc,@mysimfun,{Sys,Exp,SimOpt},{Vary},FitOpt);

So you could try downloading the development version and pasting that line in.


Re: fitting two spectra with esfit

Posted: Tue Mar 07, 2023 4:33 am
by Patto
EricWalter wrote: Mon Mar 06, 2023 12:21 pm

What version of Matlab are you using? I had problems with functions defined inside a script with older versions (I just made the function a separate .m file). But beyond that, it looks like you will overwrite your x-band data with your Q-band, I think you need to cat them together. And I think you need to scale each simulation to the experimental data separately.

I got your script to run in version 6 with matlab 2018 by replacing line 53 with the new syntax for esfit:
esfit(spc,@mysimfun,{Sys,Exp,SimOpt},{Vary},FitOpt);

So you could try downloading the development version and pasting that line in.

I do this using matlab 2020b and easyspin 5.2.33. I tried matlab 2021a and easyspin 6, it works. But I don't konw how to cat two spectra together? For easyspin 6, how do I get the fitted spectra and values?


Re: fitting two spectra with esfit

Posted: Tue Mar 07, 2023 7:22 pm
by Patto
EricWalter wrote: Mon Mar 06, 2023 12:21 pm

What version of Matlab are you using? I had problems with functions defined inside a script with older versions (I just made the function a separate .m file). But beyond that, it looks like you will overwrite your x-band data with your Q-band, I think you need to cat them together. And I think you need to scale each simulation to the experimental data separately.

I got your script to run in version 6 with matlab 2018 by replacing line 53 with the new syntax for esfit:
esfit(spc,@mysimfun,{Sys,Exp,SimOpt},{Vary},FitOpt);

So you could try downloading the development version and pasting that line in.

I've met a problem that two spectra shares different line width. How do define different line width for two spectra? THANK YOU!


Re: fitting two spectra with esfit

Posted: Tue Mar 07, 2023 8:59 pm
by EricWalter

Change the lw value in the function when you get to each, the same as you do the Exp values (you will have to Vary each separately):
Sys0.lw =Sys.lwX;
yX = pepper(Sys0, Exp, SimOpt);
Sys0.lw =Sys.lwQ;
yQ = pepper(Sys0, Exp, SimOpt);