Error in lsqcurvefit (line 225)

4 views (last 30 days)
Batula
Batula on 5 Apr 2023
Moved: the cyclist on 5 Apr 2023
I am absolutely new to the matlab.
i have 2 vectors,
xdata is 744x1 double
ydata is 744x1 double
my function is
function ydata=calcor(k,xdata)
ydata=(1-(1-k)*(xdata.^k));
end
i am trying to get k
k= lsqcurvefit(@calcor,[0 0],xdata,ydata)
it giving me error:
Error using .^
Matrix dimensions must agree.
Error in calcor (line 2)
ydata=(1-(1-k)*(xdata.^k));
Error in lsqcurvefit (line 225)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
whats is wrong with the code
  1 Comment
Mathieu NOE
Mathieu NOE on 5 Apr 2023
We know that k must be a scalar , but is it ? check its size

Sign in to comment.

Answers (1)

Torsten
Torsten on 5 Apr 2023
Moved: the cyclist on 5 Apr 2023
x0 = 0, not x0 = [0 0].
  1 Comment
Batula
Batula on 5 Apr 2023
Moved: the cyclist on 5 Apr 2023
@Torsten with a slight change of yours it worked! thank you very much for helping us

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!