Warning: Rank deficient, rank = 0, tol = NaN.

1 view (last 30 days)
Hi Dears,
I'm using lsqcurvefit to fit my data. Sometimes, when I select an initial guess I get the following error:
Warning: Rank deficient, rank = 0, tol = NaN.
My question is not about how to fix that error. Rather, I hope to see how to avoid that fitting process entirely when it detects that error!
I mean, suppose the curve fitting (using lsqcurvefit or any other optimization tool; such as: NonLinearModel.fit, etc) is located in a function that is called via a main m-file. If the previous warning is detected, then the m-file should ignore or bypass that function and proceeds normally without stopping the program on a red error message says: Error using lsqcurvefit (line 251) Function value and YDATA sizes are not equal.
All what I need is like an if-statement. If the initial guess is healthy then please fit the data; otherwise, ignore the curve fitting stage and jump to the next lines in the main m-file.
Could you please guide me in resolving this issue.
Thank you so much

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 15 Aug 2018
Have a look at
try
catch
end
That way you might be able to put the curve fitting (or other fragile attempts) in the try part and handle the occasional errors in the catch part.
HTH
  1 Comment
Sitra
Sitra on 15 Aug 2018
Awesome
Great trick and it solves my problem
Thank you so much

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!