MATLAB: Nlinfit command problem :(

gaussfitnonlinear

A gaussfit code gives an error of:
Error using nlinfit>checkWeights (line 961)
Weights must be a vector of real positive weights or a function handle that accepts a vector of
predicted response values and returns a vector of real positive weights the same size as Y.
Error in nlinfit (line 223)
nanweights = checkWeights(weights, yfit, y);
Error in Nonlinearhw (line 8)
plot(q,Astart,'-k'); [beta,R,J,covB]=nlinfit(q,A,'gaussfit',n,'Weights',dA);
Also q and A both are 161*1 matrixes.
What is the problem?? 🙁

Best Answer

From the error message: "Weights must be a vector of real positive weights ..." Are they?
  • Is dA a vector? Check with isvector.
  • Is dA a real vector? Check with isreal.
  • Are all the elements in dA positive? Check using the > operator. Remember that 0 is not positive.