Error "Attempt to reference field of non-structure array"

A place to report and discuss potential bugs
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Error "Attempt to reference field of non-structure array

Post by thanasis »

What I mean:

After making a cli run with esfit to extract the ascii file with the calculated composite spectrum (mydatafile_fitcurve.txt), while also having extracted the ascii subspectra and their sum (Cu7_total.txt) from the fitting function as I previously updated it, I do the following:

Code: Select all

load Cu7_total.txt; % Load the sum of the subspectra as derived from the fitting function (Cu_monomer + Cu_trimer)
load mydatafile_fitcurve.txt; % Load the calculated (scaled) composite spectrum as derived from esfit
ratio=mydatafile_fitcurve(:,2)./Cu7_total; % Divide the two curves point per point
plot(B,ratio)
If scaling was the only difference, shouldn't we be getting a straight horizontal line? Or would that be the case assuming a specific scaling method?
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Error "Attempt to reference field of non-structure array

Post by Stefan Stoll »

Please post a complete script that defines all parameters for the esfit call.
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Error "Attempt to reference field of non-structure array

Post by thanasis »

Script:

Code: Select all

clear all;
close all;
fname = 'skg10607.spc';
[B, spc, params] = eprload(fname);
%--------------------------------------------------------------------------
%The spin system
%--------------------------------------------------------------------------
Sys1.S=1/2;
Sys1.g=[2.064 2.244];
Sys1.lwpp = [0 6];
Sys1.Nucs = 'Cu';
Sys1.A = [0 515];

Sys2.S = 1/2;
Sys2.g = [1.74 2.18];
Sys2.gStrain = [0.29 0];
Sys2.lwpp = [0 13];
Sys2.weight = 0.8;

Exp.Temperature = 4.1; Exp.mwFreq=params.MF; Exp.CenterSweep=[((params.HCF-25.76)/10) params.HSW/10]; Exp.nPoints=params.RES;

%--------------------------------------------------------------------------
Vary1.g = [0.0 0.0];
Vary1.lwpp = [0 2];
Vary1.A = [0 0];

Vary2.g = [0.0 0.01];
Vary2.gStrain = [0 0];
Vary2.lwpp = [0 2];
Vary2.weight = 0.;

% Call the fitting function
FitOpt.Method = 'simplex diff';
FitOpt.Scaling = 'lsq1';

[BestSys,BestSpc] = esfit('decompose_v2',spc,{Sys1,Sys2},{Vary1,Vary2},Exp,[],FitOpt);
datafname = [fname,'_fitcurve.txt'];
calcdata = [B(:) BestSpc(:)];       % Arrange calculated data as an ascii file
save(datafname,'calcdata','-ascii'); % Save the calculated curve as an ascii file
decompose_v2.m:

Code: Select all

function [x,y] = decompose_v2(Sys,Exp,Opt)

[x,y_monomer] = pepper(Sys{1},Exp,Opt);
[x,y_trimer] = pepper(Sys{2},Exp,Opt);

calc_monomer = y_monomer'; save('Cu7_monomer.txt','calc_monomer','-ascii');
calc_trimer = y_trimer'; save('Cu7_trimer.txt','calc_trimer','-ascii');

figure(234);
% subplot(2,1,1)
plot(x,y_monomer)
drawnow
hold on
% subplot(2,1,2)
plot(x,y_trimer)
drawnow

y = y_monomer + y_trimer;
calc_total = y'; save('Cu7_total.txt','calc_total','-ascii');
plot(x,y)
hold off
end
Then in matlab's cli:

Code: Select all

load Cu7_total.txt; % Load the sum of the subspectra as derived from the fitting function (Cu_monomer + Cu_trimer)
load skg10607_spc_fitcurve.txt; % Load the calculated (scaled) composite spectrum as derived from esfit
ratio=skg10607_spc_fitcurve(:,2)./Cu7_total; % Divide the two curves point per point
plot(B,ratio)
The data file is the uploaded one.
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Error "Attempt to reference field of non-structure array

Post by Stefan Stoll »

You specified 'lsq1' scaling, which includes a linear baseline in the fit.
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Error "Attempt to reference field of non-structure array

Post by thanasis »

That's right!

I just tested that maxabs gives excellent agreement; minmax and lsq0 not so.

Now it seems obvious!

Thanks Stefan!
Post Reply