Problem with polyfit function

1 visualización (últimos 30 días)
D.J
D.J el 30 de Sept. de 2018
Comentada: D.J el 30 de Sept. de 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!

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Sept. de 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);
  1 comentario
D.J
D.J el 30 de Sept. de 2018
Brilliant ! Thanks a lot Walter !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by