Problem with polyfit function

1 回表示 (過去 30 日間)
D.J
D.J 2018 年 9 月 30 日
コメント済み: D.J 2018 年 9 月 30 日
Hi all,
I have 2 set of data, each of which is 31*12 (31 for number of days, and 12 for months)
Set1 = T3_All (%x-values)
Set2 = Tmax_All (%y values)
Since we don't have more than 28 or 29 days for some months, the data is filled with NAN.
when i use ployfit (code below), I am getting NaN for all values. I think that is because my arrays include NaN values.
How can I got the polyfit function to deal with the NAN values to give me the correct polyfit?
I couldn't upload any files as it seems there is a bug with the system !
Here is my code:
% Assigning arrays to data
T3_All=AllT3_Import;
Tmax_All=AllTmax_Import;
% Determining coefficients
coeff1 = polyfit(T3_All,Tmax_All,1);
And the results I am getting:
coeff1 =
NaN NaN
Any help would be highly appreciated!

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 30 日
How can I got the polyfit function to deal with the NAN values to give me the correct polyfit?
You cannot. You need to be sure not to pass in data that contains nan.
mask = ~(isnan(T3_All) | isnan(Tmax_All));
coeff1 = polyfit(T3_All(mask), Tmax_All(mask), 1);
  1 件のコメント
D.J
D.J 2018 年 9 月 30 日
Brilliant ! Thanks a lot Walter !

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by