Curve Fitting Error MATLAB in checkbounds function

49 Views Asked by At

I tried to run one example code here

x = linspace(1,100);  
y = 5 + 7*log(x);
myfittype = fittype('a + b*log(x)',...
    'dependent',{'y'},'independent',{'x'},...
    'coefficients',{'a','b'})
myfit = fit(x',y',myfittype)

I got the error message below

Error in checkbounds (line 26)

if lenlb > nvars

Error in fit>iFit (line 275) [lowerbnd, upperbnd, anError, aWarning] = checkbounds( lowerbnd, upperbnd, numcoeff );

Error in fit (line 116)

[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...

Code and error However, my code worked perfectly fine last night. I can't think of anything I did today that would possibly cause this problem. I did change the path but now I set it to default and still got this problem. Any other possible reasons?

1

There are 1 best solutions below

1
L L On

Apparently, there is another checkbounds.m function and somehow MATLAB used the first one

I ran the code

which checkbounds -all

and got

C:\Program Files\MATLAB\R2023a\toolbox\curvefit\curvefit\private\checkbounds.m % Private to curvefit

C:\Program Files\MATLAB\R2023a\toolbox\shared\optimlib\checkbounds.m

I have solved the problem by adding all the paths. I'm still not sure how MATLAB choose which checkbounds to run when there are many in the paths.