For fminsearch: ??? Attempted to access params(3); index out of bounds because numel(params)=2.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, the objective of the code below is to use fminsearch function for curve fitting purposes so that I will be able to get unknown parameters T1,T2 and C by plotting xdata against ydata which I already have in my database.
I have previously managed to find the value of parameters T1 and T2. However, when I introduced another third parameter C, I could got this error which I could not resolve:
??? Attempted to access params(3); index out of bounds because numel(params)=2.
Below is the code:
--------------------------------------------------------------------------------------------------------------------------------------- FUNCTION CODE:
function [estimates, model] = fmmintest(xdata, ydata) % A random starting point for fminsearch. start_point = rand(1, 2, 2); model = @expfun; estimates = fminsearch(model, start_point);
function [sse, FittedCurve] = expfun(params)
T1 = params(1);
T2 = params(2);
C = params(3);
FittedCurve =C{(T2^2)*(sin(xdata)).^4 +(T1^2)*(cos(xdata).^4)};
FittedCurve = cell2mat(FittedCurve);
ErrorVector = FittedCurve - ydata;
sse = sum(ErrorVector .^ 2);
end
end
Any help will be much appreciated ! Thanks !!
Regards
0 commentaires
Réponse acceptée
Matt J
le 7 Jan 2013
Modifié(e) : Matt J
le 7 Jan 2013
If you have only 3 parameters, why do you have 4 elements in your start_point array?
>> start_point=rand(1,2,2); numel(start_point)
ans =
4
That wouldn't account for the error you're seeing, however.
I'm a bit skeptical that we're seeing your exact code. It sounds like you're initializing somehow using the previous code with numel(start_point)=2
0 commentaires
Plus de réponses (2)
Sean de Wolski
le 7 Jan 2013
rand(1,2,2) will create a 1x2x2 array. Perhaps you meant rand(1,3)?
0 commentaires
Shing
le 7 Jan 2013
1 commentaire
Matt J
le 7 Jan 2013
Modifié(e) : Matt J
le 7 Jan 2013
In the error message that you showed us, numel(params)=2 implies that fminsearch thought that you were are solving a 2-parameter problem. fminsearch deduces this from numel(start_point). But in the code you showed, numel(start_point) was equal to 4. I therefore cannot see how it would have assumed you were working in R^2 if the code you showed us was actually the code being run.
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!