Why do I receive an error message when using LSQCURVEFIT in the Optimization Toolbox?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 7 Nov 2012
Modificato: MathWorks Support Team
il 25 Lug 2019
I receive the error message
>> x = lsqcurvefit(fun,x0,xdata,ydata)
Error using lsqcurvefit (line 262)
Function value and YDATA sizes are not equal.
when using LSQCURVEFIT in the Optimization Toolbox.
Risposta accettata
MathWorks Support Team
il 25 Lug 2019
Modificato: MathWorks Support Team
il 25 Lug 2019
This error message occurs when the size of the output from the objective function is different than the size of the ydata vector of values.
Please check your equation in the objective function MATLAB file to make sure that the size of the vector to be returned matches up with the ydata vector. (Pay special attention when you use () matrix multiplication or (.) element by element multiplication.)
A simple way to check the output of your objective function is to pass it your xdata and initial values (x0) to ensure that the values returned are in the right form. For example:
A = myobj(x,xdata)
% Where 'myobj' is the objective function.
Make sure that A is of the same size as the ydata vector.
Also, please check that input arguments order of the object function is correct.
In the object function for LSQCURVEFIT, the first input argument should be a coefficient x and the second input argument should be the input data xdata.
% myobj = @(xdata,x)x(1)*exp(x(2)*xdata); % Wrong
myobj = @(x,xdata)x(1)*exp(x(2)*xdata); % Correct
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!