I'm trying to plot .csv file
조회 수: 1 (최근 30일)
이전 댓글 표시
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!