polyfit returns NaN values in p
    20 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    florence briton
 el 18 de Mayo de 2015
  
    
    
    
    
    Comentada: Steven Lord
    
      
 el 9 de Dic. de 2015
            I want to do a linear regression on the response Y (attached)with a predictor vector X. Therefore, I used Matlab polyfit function: [p,s,mu]=polyfit(X,Y,1) but it returns p=[NaN,Inf]
I have Inf values in vector Y. Is it the cause?
0 comentarios
Respuesta aceptada
  John D'Errico
      
      
 el 18 de Mayo de 2015
        
      Editada: John D'Errico
      
      
 el 18 de Mayo de 2015
  
      Yes. infs in your data will surely cause NaNs, and essentially garbage results. Drop them out first if you expect something meaningful.
y = [rand(10,1);inf];
x = rand(11,1);
p = polyfit(x,y,1)
p =
   NaN   Inf
Surely you don't expect anything reasonable to come out of such a computation with INFs in it. What would the slope of such a line be with some data points at infinity? Of course, any such point at infinity would have infinite leverage.
0 comentarios
Más respuestas (1)
  carlo lefevre
      
 el 9 de Dic. de 2015
        ind = 1:length(a); k = ~isnan(a); p = polyfit(ind(k),a(k),n)
1 comentario
  Steven Lord
    
      
 el 9 de Dic. de 2015
				You probably want to use ISFINITE instead of ~ISNAN to include only finite values (excluding Inf, -Inf, and NaN) rather than including only non-NaN values (which would NOT exclude Inf or -Inf.)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



