??? Subscripted assignment dimension mismatch.

function [er]= ErrorF(x,y,p)
x=[-0.6 -0.4 -0.1 0.5 1.5];
y=[18 8 3 2 0.9];
er=y-(1./((x.*p(1))+p(2)));
end
ERROR:
??? Subscripted assignment dimension mismatch.
Error in ==> fminsearch at 191
fv(:,1) = funfcn(x,varargin{:});
Error in ==> Untitled at 3
p=fminsearch(@(p)er,[0.2 0.5])
need help with this.!!!!!

Réponses (2)

Walter Roberson
Walter Roberson le 25 Fév 2012
You call fminsearch on @(p)er but you are not passing p to er. You have not shown the code for er; you have instead shown the code for ErrorF. If you have created a variable named "er" before the fminsearch() call, by calling ErrorF yourself, then notice that variable would be a scalar rather than a function.
Question: why would you pass x and y to ErrorF if you are going to immediately reassign their values?
Suggested code:
x=[-0.6 -0.4 -0.1 0.5 1.5];
y=[18 8 3 2 0.9];
ErrorF = @(p) y-(1./((x.*p(1))+p(2)));
pval = fminsearch(ErrorF, [0.2 0.5]);
Andrei Bobrov
Andrei Bobrov le 25 Fév 2012
try this is code
x=[-0.6 -0.4 -0.1 0.5 1.5];
y=[18 8 3 2 0.9];
fun1 = @(p,x)1./(x.*p(1)+p(2));
pout = nlinfit(x,y,fun1,[.2 .5]);
x1 = linspace(-.6,1.5,100);
plot(x,y,'ko',x1,fun1(pout,x1),'r-')

Catégories

En savoir plus sur Function Creation dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by