Plot datetime with data from .csv
1 回表示 (過去 30 日間)
古いコメントを表示
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
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.
Read comma-separated value (CSV) file - https://www.mathworks.com/help/releases/R2018a/matlab/ref/csvread.html
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 Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!