import and plot dated time series
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
tilfani oussama
il 12 Feb 2018
Commentato: Ganesh
il 21 Ott 2023
Hello I have an excel files containing financial time series, two columns the first indicate the date and the second indicates values, i would like to import this file from excel to matlab and ploting a graph with date in "x " axis and in the "y" axis the values. Tnak you
2 Commenti
Akira Agata
il 13 Feb 2018
Seems that using readtable and plot functions (and maybe datetime function), you can plot it. If possible, I would like to suggest sharing your sample Excel file here.
Risposta accettata
Più risposte (2)
Peter Perkins
il 13 Feb 2018
As Akira says, use readtable and plot. In recent versions, readtable will create a datetime variable automatically, in earlier versions you may need to convert from text to datetime. In R2016b or later, convert the table to a timetable. You have one time variable and two data series, so there are various ways you might want to make a plot. Using ttplot from the File Exchange, this:
>> t = readtable('SP index.xls');
>> tt = table2timetable(t);
>> ttplot(tt)
gives me this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178943/image.png)
2 Commenti
Peter Perkins
il 13 Feb 2018
You need R2016b or later to use timetables. But "However, ttplot also works with a table that contains a datetime or duration variable, and so is also useful for R2014b-R2016a."
Viktor Bolgov
il 25 Ott 2019
Modificato: Viktor Bolgov
il 25 Ott 2019
Hello!
I have a similar problem. I try to read my measurement file recorded in the format Date Time Current: 03.06.2017 03:15:45:878301 643.1426. The file with the data is attached. I tried to apply the mentioned above commands.
>> t = readtable('01.xls');
>> tt = table2timetable(t);
>> ttplot(tt)
The execution of the first command gave me table 330x2 in the next form.
Column1 Column2
____________________________ __________
'03.06.2017 03:15:45:878301' '643.1426'
'03.06.2017 03:15:45:888320' '643.1418'
'03.06.2017 03:15:45:898340' '643.1401'
The attemt to apply command table2timetable(t) gave the next mistake.
Error using table2timetable (line 58)
Input table must contain datetime or duration vector for row times.
Any help, please. I am using Matlab 2018b.
2 Commenti
Akira Agata
il 28 Ott 2019
Before plotting it, you need to convert each column to appropriate variable type. The following is an example:
t = readtable('01.xls');
% Convert Column1 to datetime, and Column2 to double
t.Column1 = datetime(t.Column1,'InputFormat','dd.MM.yyyy hh:mm:ss:SSS');
t.Column2 = str2double(t.Column2);
tt = table2timetable(t);
plot(tt.Column1,tt.Column2)
Viktor Bolgov
il 27 Nov 2019
Dear Mr. Akira Agita!
Your advice helped me! It works! Thank you very much for your kind cooperation.
Yours sincerely,
Viktor Bolgov
Vedere anche
Categorie
Scopri di più su Calendar in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!