MATLAB Answers

turning date strings to overal minutes

2 views (last 30 days)
Hi, i have various Dat. files from which i calculate some variables, the files are named acoording to the date and time:
where: filename = year_month_day_hour_min_sec. the problem is that the program doesnt do the standard YYYYMMDDHHMMSSSS depending on values (01 is given simply as 1)
i need to make a value-time plot for the variables, so i wanted to transform the overall date in to overal minutes starting from the lowest time.
any ideas or functions that could work?


Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 1 Jan 2020
Edited: Stephen Cobeldick on 1 Jan 2020
Just use datetime, e.g.:
>> C = {...
>> D = regexp(C,'^\w+\.\w+','match','once');
>> T = datetime(D, 'inputFormat','yyyy_M_d_H_m_s.SS')
T =
31-Dec-2019 17:43:31
31-Dec-2019 17:19:36
31-Dec-2019 16:55:41
31-Dec-2019 16:55:41
01-Jan-2020 12:07:05
and you can plot the datetime object directly (no need to count minutes from some random epoch):
>> V = rand(1,numel(T));
>> plot(T,V)
  1. your timestamps are not in chronological order, the plot will show this too.
  2. converting to datetime has not made your fractional seconds disappear: the default 'format' simply does not show fractional seconds. Change the 'format' if you want to see them displayed.

  1 Comment

Sign in to comment.

More Answers (0)

Sign in to answer this question.