fminsearch with three parameters

I'm trying to do an fminsearch on a function with three free variables and I get the following message :
??? Attempted to access p(3); index out of bounds because numel(p)=2.

Error in ==> @(p)lorfit(Table1,p(1),p(2),p(3))


Error in ==> fminsearch at 205
fv(:,1) = funfcn(x,varargin{:});

here's the code for my function lorfit :
function [ ansa ] = lorfit(x,G,x0,H)
ansa = 0;
for c = 1:length(x)
ansa = ansa + (x(c,2) - (H/(2*((x(c,1)-x0)^2+(G/2)^2))))^2;
end
ansa = sqrt(ansa);

end

Can someone tell me what I'm doing wrong?
0
Bob
1/19/2011 9:14:05 PM
comp.soft-sys.matlab 209991 articles. 11 followers. lunamoonmoon (258) is leader. Post Follow

1 Replies
749 Views

Similar Articles

[PageSpeed] 11

On 1/19/2011 4:14 PM, Bob Garrett wrote:
> I'm trying to do an fminsearch on a function with three free variables
> and I get the following message :
> ??? Attempted to access p(3); index out of bounds because numel(p)=2.
>
> Error in ==> @(p)lorfit(Table1,p(1),p(2),p(3))

> Can someone tell me what I'm doing wrong?

Whatever code is calling FMINSEARCH is apparently calling it with a 
starting vector that has fewer than three elements.  Set a breakpoint at 
that line of code, run it, and see what's being passed in.

Hope this helps.
0
Peter
1/20/2011 2:26:36 PM
Reply: