Error when fitting polyfit curve
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    emily bristow
 el 12 de Dic. de 2020
  
Trying to plot a polynomial curve onto my time series but keeps coming up with 'Inputs must be floats, namely single or double'
This is the code I've got:
% plot time series
X = Months;
X = categorical({'March','April','May','June','July','August','November'});
M = reordercats(X,{'March','April','May','June','July','August','November'});
Y = AverageDO;
plot(M,Y,'*');
p = polyfit(M,Y,1);
The excel sheet attached is the timeseries data.
0 comentarios
Respuesta aceptada
  dpb
      
      
 el 12 de Dic. de 2020
        
      Editada: dpb
      
      
 el 13 de Dic. de 2020
  
      Error is exactly what it says--you wrote:
X = categorical({'March','April','May','June','July','August','November'});
M = reordercats(X,{'March','April','May','June','July','August','November'});
so M is a categorical variable which polyfit is not equipped to handle.
Use
>> M=month(datetime(string(X),'inputformat','MMM'))
M =
     3     4     5     6     7     8    11
>> 
or some other way to generate the months as numeric.
I THINK some of the Statistics and/or Curve Fitting toolbox routines may know how to handle categorical variables but I don't recall for absolute sure otomh.
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Time Series en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!