Using "isfinite" to skip NAN data

2 ビュー (過去 30 日間)
D.J
D.J 2018 年 10 月 1 日
回答済み: D.J 2018 年 10 月 1 日

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 get the polyfit function pass the data that contains nan, using isfinite?

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

P.S. I have posted this question before, although the answer provided was excellent, but it solved the problem using "mask". We are required to use "isfinite".

Many thanks

採用された回答

Bruno Luong
Bruno Luong 2018 年 10 月 1 日
編集済み: Bruno Luong 2018 年 10 月 1 日
isvalid = isfinite(T3_All) & isfinite(Tmax_All);
coeff1 = polyfit(T3_All(isvalid),Tmax_All(isvalid),1)

You would recognize it is a mask, if your professor doesn't like it, ask why, because the mo mask solution is slower and less visible.

ikeep = find(isfinite(T3_All) & isfinite(Tmax_All));
coeff1 = polyfit(T3_All(ikeep),Tmax_All(ikeep),1)

その他の回答 (2 件)

KSSV
KSSV 2018 年 10 月 1 日

You have two options:

1. Use interpolation to fill the nan's and then use polyfit.

2. Remove NaN's using isnan and then fit the data.


D.J
D.J 2018 年 10 月 1 日
Perfect results ! Thanks a lot Bruno !

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by