Plot datetime with data from .csv

조회 수: 3 (최근 30일)
Beñat Estala
Beñat Estala 2018년 11월 9일
댓글: Peter Perkins 2018년 11월 15일
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
Yash Ubale
Yash Ubale 2018년 11월 12일
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 2018년 11월 15일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by