Polyfitting warning

19 ビュー (過去 30 日間)
olski one
olski one 2011 年 5 月 15 日
hey guys,
when I am using the polyfit function i get the following error printing in the command window:
"Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT. "
I was wondering if there is a way to suppress the printing of this warning in the command window. I know what I am trying to do is correct for this situation. but I just wish it would stop printing it.
  2 件のコメント
Matt Fig
Matt Fig 2011 年 5 月 15 日
This is not an error, but a warning message. An error would prevent you from getting a return value...
olski one
olski one 2011 年 5 月 15 日
yeah sorry thats what i meant

サインインしてコメントする。

採用された回答

Matt Fig
Matt Fig 2011 年 5 月 15 日
I'll take you at your word that you know what you are doing.
ws = warning('off','all'); % Turn off warning
P = polyfit(x,y,N);
warning(ws) % Turn it back on.

その他の回答 (2 件)

John D'Errico
John D'Errico 2011 年 5 月 15 日
If you are getting that error message, then you are probably computing garbage for the coefficients of the polynomial. Don't suppress the warning, even while that IS possible to do. (help warning)
Deal with the problem and the message goes away. It is usually either due to overfitting the data with too high order of a model, or with poor scaling of your data. If you start suppressing the warning, then you won't be told when you DO have a problem. Closing your eyes does not make a problem go away.

Arturo Moncada-Torres
Arturo Moncada-Torres 2011 年 5 月 15 日
Mmm, there is a cheap way:
try
% The code with the polyfit function goes here
catch
end
However I really recommend you to check that what you are doing is correct.
Hope it helps ;-) .
  2 件のコメント
Matt Fig
Matt Fig 2011 年 5 月 15 日
TRY-CATCH has no effect with Warnings...
Arturo Moncada-Torres
Arturo Moncada-Torres 2011 年 5 月 16 日
Oh really? I think then I have used it with error messages only. Anyway, it is good to know, thanks! =)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by