I'm trying to plot .csv file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Willian Alexander Correa Reyes
el 21 de Jun. de 2021
Comentada: Star Strider
el 21 de Jun. de 2021
trying to graph the time series vs variables but it produces an error in the time column, can someone help me, indicating where the error is here please
T = readtable('prueba.csv')
T.Date.Format = 'yyyy-MM-dd';
T.Time.Format = 'HH:mm:ss';
myDatetime = T.Date + timeofday(T.Time)
y1 = T{:,7};
plot(myDatetime,[y1],'r-','lineWidth',1)
When I try to graph I get an error in the line highlighted in bold, tks for your support.
0 comentarios
Respuesta aceptada
Star Strider
el 21 de Jun. de 2021
Editada: Star Strider
el 21 de Jun. de 2021
The ‘Time’ variable is a duration array, so the timeofday call is not necessary.
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/660400/prueba.csv', 'VariableNamingRule','preserve')
MyDateTime = T1.Date + T1.Time;
MyDateTime.Format = 'yyyy-MM-dd HH:mm:ss';
T2 = [T1(:,1) table(MyDateTime) T1(:,[4:end])]
EDIT — (21 Jun 2021 at 19:58)
With respect to the plot —
figure
plot(T2.MyDateTime, T2.('{pd}'), '-r', 'LineWidth',1)
grid
xlabel('Date & Time')
ylabel('\{pd\}')
title('\{pd\} as a function of time')
.
2 comentarios
Star Strider
el 21 de Jun. de 2021
There was no release posted, so I assume R2012a. The 'VariableNamingRule' (or variations of it) were introduced after R2017b. Just refer to the variables by their column numbers instead.
In R2021a, the ‘Time’variable is automatically a duration array. Using the time function on the ‘Time’ variable should convert it to a duration array. Try that. If it does, the rest of my code should work.
.
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time 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!