I'm trying to plot .csv file
1 回表示 (過去 30 日間)
古いコメントを表示
Willian Alexander Correa Reyes
2021 年 6 月 21 日
コメント済み: Star Strider
2021 年 6 月 21 日
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 件のコメント
採用された回答
Star Strider
2021 年 6 月 21 日
編集済み: Star Strider
2021 年 6 月 21 日
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 件のコメント
Star Strider
2021 年 6 月 21 日
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.
.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!