import and plot dated time series
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
tilfani oussama
le 12 Fév 2018
Commenté : Ganesh
le 21 Oct 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 commentaires
Akira Agata
le 13 Fév 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.
Réponse acceptée
Plus de réponses (2)
Peter Perkins
le 13 Fév 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 commentaires
Peter Perkins
le 13 Fév 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
le 25 Oct 2019
Modifié(e) : Viktor Bolgov
le 25 Oct 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 commentaires
Akira Agata
le 28 Oct 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
le 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
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!