Plot datetime with data from .csv
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I want to plot data with dates, dates in x array and data un y arrays, but I'm having problems with the next code:
clc
clear
close all
filename='prueba.csv';
data = importfileCSVprueba(filename);
Tiempo = datetime(data(2:end,1),'InputFormat','yyyy-MM-dd HH:mm:ss.S');
Valor = data(2:end,2);
figure
plot(Tiempo,Valor, '-o')
grid
xlabel('Tiempo')
ylabel('Valor')
Thanks.
2 comentarios
Yash Ubale
el 12 de Nov. de 2018
Firstly, there is no function called 'importfileCSVprueba', use 'csvread' instead.
Also, it seems like the data in the first column of the 'prueba.csv' file is not consistent.
To read more about reading data from '.csv' files, follow the link mentioned below.
Read comma-separated value (CSV) file - https://www.mathworks.com/help/releases/R2018a/matlab/ref/csvread.html
Peter Perkins
el 15 de Nov. de 2018
I recommend NOT starting out with csvread. readtable is a much better starting point in the long run. Among other things, in recent versions of MATLAB, it will in many cases create datetimes for you automatically.
In your case, the timestamps are in a bit of an unusual format, three formats in fact -- there are trailing Z's in the last third of them, and embedded T's in the last quarter of them. So:
1) clean up the file, and specify a format to readtable (or better yet, use detectimportoptions), or
2) read the timestamps as text, and convert them to datetimes in three steps, with three different formats.
Respuestas (0)
Ver también
Categorías
Más información sobre Tables 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!