MATLAB Answers

Custim fit doesn't work when adding problem values

2 views (last 30 days)
Lars Duelund
Lars Duelund on 1 Mar 2016
Commented: Julian Groß-Funk on 16 Sep 2021
Dear All
I am trying to fit some experimental data to a custom fit by using the fit function from the Curve Fitting Toolbox. In my fit I have 3 'problem' parameter (i.e a value i don't fit) which changes for each data point. But when I include them in fit function I get the error:
Error using fittype/testCustomModelEvaluation (line 12) Expression testMem(x,DH,K, Cdi,Vcell,dCl0i) is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated: Error in fittype expression ==> testMem(x,DH,K, Cdi,Vcell,dCl0i) ??? Index exceeds matrix dimensions.
My fit function is:
function y=testMem(x,DH,K, Cdi,Vcell,dCl0i)
y=zeros(size(x));
for i=1:length(x)
y(i)=dCl0i(i)*Vcell(i).*Cdi(1).*DH.*(K./((1+K.*x(i)).^2));
end
end
And I do the fit by the following:
ftype=fittype('testMem(x,DH,K, Cdi,Vcell,dCl0i)','problem', {'Cdi','Vcell','dCl0i'})
f=fit(ClipCelli,data(:,1)*1e-6,ftype,'problem', {Cdert0i,Vtoti,dClipCelli})
All the data and all the 'problem' numbers are 25 x 1 vectors of the type double. And the function IS working if i try ti with reasonable value for my two fit parameters (DH, K)
If I remove all the problem values from my fit is works (in the sense that I don't get any error messages, the fit is totally off).
Any ideas for what is going on here? Any hints what i should check? ALL help is highly appropriated
  1 Comment
Julian Groß-Funk
Julian Groß-Funk on 16 Sep 2021
Problem variables are only allowed to be one character long. That means only a-z and A-Z are available as problem variables

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by