Creation timeSeries using a datetime variable

46 visualizaciones (últimos 30 días)
Cedric Mariage
Cedric Mariage el 10 de Ag. de 2015
Editada: per isakson el 15 de Ag. de 2015
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,

Respuesta aceptada

Adam Barber
Adam Barber el 12 de Ag. de 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 comentario
Cedric Mariage
Cedric Mariage el 13 de Ag. de 2015
Thanks for your answer , I manage to improve the speed of the code so it's working now.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Calendar en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by