I'm trying to plot .csv file
1 view (last 30 days)
Show older comments
Willian Alexander Correa Reyes
on 21 Jun 2021
Commented: Star Strider
on 21 Jun 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 Comments
Accepted Answer
Star Strider
on 21 Jun 2021
Edited: Star Strider
on 21 Jun 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 Comments
Star Strider
on 21 Jun 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.
.
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!