curve-fitting problem: Unrecognized option name 'showstatus' in OPTIMSET ?
Show older comments
Hi all,
I'm having problems fitting a custom model because I keep getting an error message I don't know what to do about.
I have vector data X and vector data Y, and I want to curve-fit (nonlinearleastsquares) a custom equation.
Here's a snippet of code:
given: independent data vector X, dependent data vector Y
fo=fitoptions('Method', 'NonlinearLeastSquares', 'StartPoint', [1, 4]);
g = fittype( @(a, b, x) a*((x-b).^2), 'options', fo)
[fitobject,gof,output] = fit(X, Y, g);
This generates an error message:
Error using fit>iFit (line 340)
Unrecognized option name 'showstatus'. See OPTIMSET for possibilities.
Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
I have used curve-fitting with library models without any problems. The error occurs when I try to fit a custom model.
Can anyone help?
Thanks,
Andy
15 Comments
Hmmm. Can't seem to reproduce that (in R2018a),
a=1;b=2;
X=linspace(0,1,100).';
Y=a*(X-b).^2;
fo=fitoptions('Method', 'NonlinearLeastSquares', 'StartPoint', [1, 4]);
g = fittype( @(a, b, x) a*((x-b).^2), 'options', fo)
[fitobject,gof,output] = fit(X, Y, g);
>> fitobject
fitobject =
General model:
fitobject(x) = a*((x-b).^2)
Coefficients (with 95% confidence bounds):
a = 1 (1, 1)
b = 2 (2, 2)
dpb
on 21 Jun 2019
Which release? I get no issues with the above code with R2017b...
>> X=1:10;X=X(:);Y=rand(size(X));
>> fo=fitoptions('Method', 'NonlinearLeastSquares', 'StartPoint', [1, 4]);
>> g = fittype( @(a, b, x) a*((x-b).^2), 'options', fo)
g =
General model:
g(a,b,x) = a*((x-b).^2)
>> [fitobject,gof,output] = fit(X, Y, g);
>> fitobject
fitobject =
General model:
fitobject(x) = a*((x-b).^2)
Coefficients (with 95% confidence bounds):
a = 0.04691 (0.009478, 0.08434)
b = 5.02 (3.443, 6.596)
>>
Andreas Baas
on 21 Jun 2019
Matt J
on 21 Jun 2019
Please copy/paste the full error message. The part you posted doesn't show the full stack of function calls. Also, show us the output of
which -all fit
Andreas Baas
on 21 Jun 2019
Andreas Baas
on 21 Jun 2019
Run the code in a script, not from the command line. Better yet, run it inside a function. If you do, you will see a longer stack of errors including the top level function, e.g.,
Error using fit>iFit (line 135)
X and Y must have the same number of rows.
Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in test (line 8)
[fitobject,gof,output] = fit(X(1:end-1), Y, g);
Andreas Baas
on 21 Jun 2019
Matt J
on 21 Jun 2019
Hmmm. Very puzzling. Oh well, when in doubt...reboot.
dpb
on 21 Jun 2019
Peculiar! Everything with fit looks OK...altho it's in the options object that the issue lies in that the field name isn't being recognized. So, what does
which -all fitoptions
show?
If I use optimget() on the object a 'showstatus' property isn't shown nor is it documented in the fitoptions function doc, at least on R2017b. Nor do I see such a Name,Value pair in current doc https://www.mathworks.com/help/curvefit/fitoptions.html?s_tid=doc_ta#namevaluepairarguments
Peculiar, indeed to have generated such a reference...that Matt didn't find same issue on another install or R2018a is most peculiar, indeed. Almost looks like there must be some as-yet unimplemented new code in your function that isn't supposed to be able to be executed or the build included code not intended. Just bizarre...
I supposed you have tried the expedient of
clear all
and a restart of new MATLAB session to see is symptom would heal itself...
Andreas Baas
on 21 Jun 2019
Matt J
on 21 Jun 2019
Try rerunning the code after
>> dbstop if caught error
Andreas Baas
on 21 Jun 2019
Andreas Baas
on 21 Jun 2019
dpb
on 21 Jun 2019
But that does show that the property name 'showstatus' was somehow passed to the optimget routine and as doc shows, there isn't any such property.
Now, how that got generated as a parameter is the kicker...perhaps there is some sort of namespace resolution thingie going on and it did somehow get into a ML object when should have been calling some Java method--TMW has got everything so entwined now it's impossible to know just what might end up using it.
You could just confirm the input arguments to the function when in debug mode, but backtracking to how that got generated is, as you say, probably only something the developers can manage.
Looks like time for an official bug report to me...
Answers (2)
Not much more informative, unfortunately...
But now that you've trapped the error with dbstop you can dbup and dbdown through the call stack and investigate how that call was made...
Personally, I wonder why any code in R2018a is using optimset. It should be deprecated in that version in favor of optimoptions. I begin to wonder if code from a previous partially uninstalled version of Matlab has made its way into the mix. A complete, clean reinstall of Matlab might be necessary. "Clean" means you delete the entire R2018a install folder before re-installing.
2 Comments
"I wonder why any code in R2018a is using optimset. It should be deprecated in that version in favor of optimoptions"
But, TMW has made such a convoluted mess out of all these it's impossible to know what is/isn't "the right stuff!" The doc for optimset says optimoptions is recommended instead of optimset for all solvers except fzero, fminbnd, fminsearch, and lsqnonneg" until they've changed their tune in current release. It's absolutely impossible to keep up... :(
To make it even worse, optimset and optimoptions are defined for the optimization routines in the Optimization Toolbox; fit and fitoptions belong to their own TB and have a different class name.
It's just a proverbual bollux of competing stuff stumbling all over itself. There doesn't seem to be any one coherent design for Matlab at all, any more...
J.D. Johnston
on 18 Feb 2023
Edited: J.D. Johnston
on 18 Feb 2023
Not sure if this is helpful, but I had the same error. It had something to do with one of the custom subroutines included in my PATH. When I revised everything in PATH to just the basics, custom fitting worked fine.
Andreas Baas
on 19 Feb 2023
0 votes
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

