Filter löschen
Filter löschen

I'm trying to plot .csv file

1 Ansicht (letzte 30 Tage)
Willian Alexander Correa Reyes
Kommentiert: Star Strider am 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.

Akzeptierte Antwort

Star Strider
Star Strider am 21 Jun. 2021
Bearbeitet: Star Strider am 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')
T1 = 78×8 table
No. Date Time mm {p} {t} {pd} {q} ___ __________ ________ ___ ______ ______ ________ ______ 1 2021-06-01 00:00:00 615 175.27 77.267 4.9991 784.46 2 2021-06-01 00:00:05 175 175.39 77.267 9.1318 1104.3 3 2021-06-01 00:45:35 198 172.1 76.443 0.79982 501.5 4 2021-06-01 00:45:45 163 171.62 76.914 1.4664 472.85 5 2021-06-01 01:31:05 195 175.63 75.972 9.665 1070.8 6 2021-06-01 01:31:15 210 169.3 74.794 6.6655 0 7 2021-06-01 02:16:35 188 178.07 76.384 -0.3 1021.8 8 2021-06-01 02:16:45 209 169.43 75.559 3.966 0 9 2021-06-01 03:02:15 166 177.22 74.617 -0.20002 652.62 10 2021-06-01 03:02:25 177 170.89 73.91 -0.16669 0 11 2021-06-01 03:47:45 182 177.7 74.912 3.3327 720.6 12 2021-06-01 03:47:55 196 178.43 73.675 14.064 0 13 2021-06-01 04:33:25 186 171.01 75.029 -0.20002 1330.3 14 2021-06-01 04:33:35 201 175.02 57.951 153.41 3392.7 15 2021-06-01 05:18:55 180 3.7731 78.504 -0.3 0 16 2021-06-01 05:19:05 193 4.8685 78.445 27.929 594.22
MyDateTime = T1.Date + T1.Time;
MyDateTime.Format = 'yyyy-MM-dd HH:mm:ss';
T2 = [T1(:,1) table(MyDateTime) T1(:,[4:end])]
T2 = 78×7 table
No. MyDateTime mm {p} {t} {pd} {q} ___ ___________________ ___ ______ ______ ________ ______ 1 2021-06-01 00:00:00 615 175.27 77.267 4.9991 784.46 2 2021-06-01 00:00:05 175 175.39 77.267 9.1318 1104.3 3 2021-06-01 00:45:35 198 172.1 76.443 0.79982 501.5 4 2021-06-01 00:45:45 163 171.62 76.914 1.4664 472.85 5 2021-06-01 01:31:05 195 175.63 75.972 9.665 1070.8 6 2021-06-01 01:31:15 210 169.3 74.794 6.6655 0 7 2021-06-01 02:16:35 188 178.07 76.384 -0.3 1021.8 8 2021-06-01 02:16:45 209 169.43 75.559 3.966 0 9 2021-06-01 03:02:15 166 177.22 74.617 -0.20002 652.62 10 2021-06-01 03:02:25 177 170.89 73.91 -0.16669 0 11 2021-06-01 03:47:45 182 177.7 74.912 3.3327 720.6 12 2021-06-01 03:47:55 196 178.43 73.675 14.064 0 13 2021-06-01 04:33:25 186 171.01 75.029 -0.20002 1330.3 14 2021-06-01 04:33:35 201 175.02 57.951 153.41 3392.7 15 2021-06-01 05:18:55 180 3.7731 78.504 -0.3 0 16 2021-06-01 05:19:05 193 4.8685 78.445 27.929 594.22
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 Kommentare
Willian Alexander Correa Reyes
Excuse the question, does it have to do with R2017b? Because I have tried to run the script that you have provided and it throws me an error in the console, I have also deleted the 'VariableNamingRule' and 'Preserve', because it did not allow me to continue with the iteration
T1 = readtable('prueba.csv')
MyDateTime = T1.Date + T1.Time;
MyDateTime.Format = 'yyyy-MM-dd HH:mm:ss';
T2 = [T1(:,1) table(MyDateTime) T1(:,[4:end])]
figure
plot(T2.MyDateTime, T2.('{pd}'), '-r', 'LineWidth',1)
grid
xlabel('Date & Time')
ylabel('\{pd\}')
title('\{pd\} as a function of time')
Command Window said:
Error using Untitled4 (line 2)
Addition is not defined between datetime arrays.
Tks
Star Strider
Star Strider am 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.
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by