Problem with polyfit function

1 view (last 30 days)
D.J
D.J on 30 Sep 2018
Commented: D.J on 30 Sep 2018
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!

Accepted Answer

Walter Roberson
Walter Roberson on 30 Sep 2018
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);

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!