Page 1 of 1

globally fitting multiple spectra with esfit

Posted: Tue Feb 06, 2018 6:55 am
by jojo21
Hello,

when I try to start a fit using the example "globally fitting multiple spectra" in the Easyspin documentation with the following command

Code: Select all

esfit('globalfit',{spec_X(:,2),spec_Q(:,2)},Sys1,Vary1,Exp,SimOpt,FitOpt);
, (where spec_x and spec_Q are matrices containing the B-values in the first column and the intensities in the second column) I always get the following error message:
Error using esfit
Second parameter must be experimental data.
Unfortunately, due to the different number of data points, I cannot combine the X- (4096 data points) and Q-band spectrum (3000 data points) in one matrix.

So my question is: How do you enter the experimental spectral data into esfit if you want to make a global fit of two spectra?

Re: globally fitting multiple spectra with esfit

Posted: Tue Feb 06, 2018 9:47 am
by joscha_nehrkorn
Have you tried the following?

Code: Select all

esfit('globalfit',[spec_X(:,2);spec_Q(:,2)]',Sys1,Vary1,Exp,SimOpt,FitOpt);
Check the size of the different vectors:

Code: Select all

spec_X(:,2) 
should have size 4096 x 1,

Code: Select all

 spec_Q(:,2) 
3000 x 1. Then

Code: Select all

[spec_X(:,2);spec_Q(:,2)]
should have 7096 x 1 and

Code: Select all

[spec_X(:,2);spec_Q(:,2)]'
1 x 7096.

Re: globally fitting multiple spectra with esfit

Posted: Wed Feb 07, 2018 5:19 am
by jojo21
Thanks with the code

Code: Select all

esfit('globalfit',[spec_X(:,2);spec_Q(:,2)]',Sys1,Vary1,Exp,SimOpt,FitOpt);
esfit runs and open the GUI.

But now I get the following error message when trying to start a fit in the GUI:
Reference to non-existent field 'scale'.

Error in globalfit (line 13)
scale = Sys.scale; % custom field for relative scaling

Error in esfit

Error in esfit_simplex

Error in esfit

Error while evaluating UIControl Callback
I get this error message even though I have defined "Sys.scale = 20" (or any other number) in the script.

The code for the user-defined simulation function "globalfit" is defined (in analogy to the example "globally fitting multiple spectra" in the easyspin documentation) as follows:

Code: Select all

function y = globalfit(Sys,Exp,Opt)

% X-band:
Exp.mwFreq = Exp.mwFreq_X;             % exact measurement frequency read out via eprload from spectrum file
Exp.nPoints = Exp.nPoints_X;           % number of data points read out via eprload from spectrum file
y1 = chili(Sys,Exp,Opt);               % row vector y1 with simulated data

% Q-band:
Exp.mwFreq = Exp.mwFreq_Q;
Exp.nPoints = Exp.nPoints_Q;
y2 = chili(Sys,Exp,Opt);               % row vector y2 with simulated data

scale = Sys.scale;                     % custom field for relative scaling

% concatenate the spectra:
y = [y1(:); scale*y2(:)];
So what's the problem? Please help.