Problem with polyfit function
1 次查看(过去 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!
0 个评论
采纳的回答
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!