Creation timeSeries using a datetime variable

46 次查看(过去 30 天)
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,

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by