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
fitting two spectra with esfit
fitting two spectra with esfit
- Attachments
-
- xq.m
- (1.72 KiB) Downloaded 387 times
-
- User
- Posts: 13
- Joined: Mon Dec 28, 2015 3:49 pm
Re: fitting two spectra with esfit
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
EricWalter wrote: ↑Mon Mar 06, 2023 12:21 pmWhat 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
EricWalter wrote: ↑Mon Mar 06, 2023 12:21 pmWhat 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!
-
- User
- Posts: 13
- Joined: Mon Dec 28, 2015 3:49 pm
Re: fitting two spectra with esfit
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);