Problem with polyfit function

조회 수: 5 (최근 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 CenterFile Exchange에서 Array and Matrix Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by