Brace Indexing Error

General forum for EasySpin: questions, how to's, etc.
Post Reply
etraore
Newbie
Posts: 1
Joined: Thu Jul 25, 2024 9:22 am

Brace Indexing Error

Post by etraore »

Hello,

I am trying to run esfit but I am coming across this unusual error:

Code: Select all

Brace indexing is not supported for variables of this type.

Error in esfit

Error in XX_Simulation (line 26)
esfit(spc,@pepper,Sys1,SysVary1,Exp,Opt);

Below are the lines of code I'm working with:

Code: Select all

clear, clc, clf

[B,spc] = eprload('XX');
B=B*0.1;

Exp.mwFreq = 9.373199; %GHz
Exp.Range = [min(B), max(B)]; %mT
Exp.nPoints = 2048;
Exp.ModAmp = 0.6; %mT
Exp.Temperature = 30; %Kelvin
Opt.GridSize = 50;

%%
Sys1.g = [6.68 2.9 1.6];
Sys1.gStrain = [0.3 0.2 0.25];
Sys1.Nucs = '59Co';
Sys1.A = [400 100 100]; %MHz
SysVary1.g = [1 1 0.5];
SysVary1.gstraing = [0.3 0.2 0.25];
SysVary1.A = [300 75 75];

[Bfit,spcfit1] = pepper(Sys1,Exp,Opt);
spcfit1 = spcfit1*max(spc)/max(spcfit1)*1;

plot(B,spc,Bfit,spcfit1)
esfit(spc,@pepper,Sys1,SysVary1,Exp,Opt);

As you can see, there are no braces in what I've written so I am unsure what the problem is. All I know is that there is a problem with my esfit code.

Any help would be appreciated!
-E

Stefan Stoll
EasySpin Creator
Posts: 1127
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Brace Indexing Error

Post by Stefan Stoll »

Your esfit call is not correct. Use esfit(spc,@pepper,{Sys1,Exp,Opt},{SysVary1});.

Also, SysVary1.gstraing probably should be SysVary1.gStrain.

agleason
Newbie
Posts: 1
Joined: Thu Mar 27, 2025 9:11 am

Re: Brace Indexing Error

Post by agleason »

I am receiving a similar error:

Brace indexing is not supported for variables of this type.

Error in esfit

Error in untitled (line 76)
esfit(spc, @pepper, Sys1, Vary1); % Fitting function call

this is the code I am working with:

clear, clc, clf

%%

[B,spc] = eprload('AG21_PFLAE23_hv_D4SAM_40K_3mW_3G.DSC');
[B,spccav] = eprload('AG_buffer_40K_3mW_3G.DSC');
spc1 = spc - spccav;
base0 = spc1(1);
spc2 = spc1 - base0;
plot(B,spc2)

% Experimental parameters
Exp.mwFreq = 9.378; % from par.MWFQ
Exp.Range = [min(B)/10,max(B)/10];
Exp.nPoints = numel(spc2);

%% Define Spin-System For Simulation

Sys1.S = [1/2];
Sys1.g = [2.0075 2.0015 2.00];
Sys1.lw = [1.0];
Sys1.Nucs = '1H, 1H, 1H';
Sys1.A = [-15 -105 -50; -20 -90 -50; 80 85 100]; % MHz
Sys1.AFrame = [0 120 0; 120 0 0; 40 0 0]*pi/180;
Sys1.HStrain = [10 10 10];
Sys1.weight = 0.9;

Sys2.S = [1/2];
Sys2.g = [2.0075 2.0015 2.00];
Sys2.lw = [1.0];
Sys2.Nucs = '2H, 2H, 2H';
Sys2.A = [-15 -105 -50; -20 -90 -50; 80 85 100]/6.514; % MHz
Sys2.AFrame = [0 120 0; 120 0 0; 40 0 0]*pi/180;
Sys2.HStrain = [10 10 10];
Sys2.weight = 0.1;

Opt.Method = 'perturb2'; % Second-order perturbation theory.
% Speeds ups your simulation considerably whith some loss of accuracy.

[Bsim, spcsim1] = pepper(Sys1,Exp); % simulation of cw solid-state EPR
specsim1 = rescale(spcsim1, min(spc2), max(spc2));

[Bsim, spcsim2] = pepper(Sys2,Exp); % simulation of cw solid-state EPR
specsim2 = rescale(spcsim2, min(spc2), max(spc2))

specsim3 = specsim1 + specsim2;

plot(B,spc2,'-k', Bsim*10,specsim3,'-r');



%% Define Varying Parameters for Fitting

Vary1.g = [0.002 0.002 0.002]; % g-values for the fit
Vary1.lwpp = [0.2]; % Linewidth parameters for the fit
Vary1.A = [5]; % Hyperfine coupling parameters for the fit

% Define Simulation and Fitting Options
SimOpt.Method = 'perturb'; % Perturbation method
FitOpt.Scaling = 'maxabs'; % Scaling method for fit
FitOpt.Method = 'simplex fcn'; % Fitting method (simplex)

% Ensure 'Sys1' is a struct with the required fields
Sys1.S = [1/2]; % Spin value
Sys1.g = [2.0075 2.0015 2.00]; % g-tensor values
Sys1.lw = [1.0]; % Linewidth
Sys1.Nucs = '1H, 1H, 1H'; % Nuclei involved
Sys1.A = [-15 -105 -50; -20 -90 -50; 80 85 100]; % Hyperfine interaction (MHz)
Sys1.AFrame = [0 120 0; 120 0 0; 40 0 0]*pi/180; % A-frame parameters (converted to radians)
Sys1.HStrain = [10 10 10]; % Hyperfine strain
Sys1.weight = 0.9; % Weight for this system

% Now call esfit function
esfit(spc, @pepper, Sys1, Vary1, fit0pt); % Fitting function call

%% Plotting the Output of Fitting

figure
plot(fit1.expSpec);
hold on
plot(fit1.fitSpec, 'g');


%% Export Data, Sim, and/or Fit

data = [B(:) spc2(:) specsim1(:)];
xlswrite('20240515_EpeE_SAM_hv_sim',data);

thanks for the help!

Post Reply