??? 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.!!!!!

답변 (2개)

Walter Roberson
Walter Roberson 2012년 2월 25일

0 개 추천

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 2012년 2월 25일

0 개 추천

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-')

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

질문:

2012년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by