Plot datetime with data from .csv

1 Ansicht (letzte 30 Tage)
Beñat Estala
Beñat Estala am 9 Nov. 2018
Kommentiert: Peter Perkins am 15 Nov. 2018
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 Kommentare
Yash Ubale
Yash Ubale am 12 Nov. 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.
Peter Perkins
Peter Perkins am 15 Nov. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Tables 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