Azzera filtri
Azzera filtri

Creation timeSeries using a datetime variable

34 visualizzazioni (ultimi 30 giorni)
Hi- I'm new to matlab world and I do have some issue dealing with the timeseries
I have two arrays
  • One time array(name time) which is a string cell array like this "dd-MM-yyy HH:mm:SS"
  • One array which represents my value for each time
I found a solution but it’s quite slow
% transformed my time array in datetime
Time2 = datetime(time,'InputFormat','dd-MM-yyyy HH:mm:SS')
%transforme my datetime array in date string
Time3= datestr(Time2)
%Create the timeseries
Ts = timeseries ( data,Time3)
This code is working but it's very slow is that possible to improve this?
Thanks in advance
Regards,

Risposta accettata

Adam Barber
Adam Barber il 12 Ago 2015
Hi Cedric,
If you already have your dates in a cell array string format, you should not need to convert to datetime in order to create a timeseries. For example, see the code below
%%Generate 100 random dates with a specified string format
datenumbers = rand(100,1)*now;
datenumbers = sort(datenumbers); % put them in increasing order
dateStrings = datestr(datenumbers, 'dd-mm-yyyy HH:MM:SS');
%%At this point "dateStrings" should be just like the data you have
Ts = timeseries(data, dateStrings);
Currently you cannot create a timeseries with "datetimes", but using a date string should work. If this is still slow for you, you may want to post either your data and full code or the results of running the profiler on the code (hit the "Run and Time" button).
Hope that helps,
-Adam
  1 Commento
Cedric Mariage
Cedric Mariage il 13 Ago 2015
Thanks for your answer , I manage to improve the speed of the code so it's working now.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time 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!

Translated by