turning date strings to overal minutes

조회 수: 1 (최근 30일)
yonatan ossia
yonatan ossia 2020년 1월 1일
댓글: yonatan ossia 2020년 1월 2일
Hi, i have various Dat. files from which i calculate some variables, the files are named acoording to the date and time:
2019_12_31_17_43_31.39-Isd
2019_12_31_17_19_36.39-Ig
2019_12_31_16_55_41.38-Ig
2019_12_31_16_55_41.38-Isd
2020_1_1_12_7_5.13-Isd
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?

채택된 답변

Stephen23
Stephen23 2020년 1월 1일
편집: Stephen23 2020년 1월 1일
Just use datetime, e.g.:
>> C = {...
'2019_12_31_17_43_31.39-Isd'
'2019_12_31_17_19_36.39-Ig'
'2019_12_31_16_55_41.38-Ig'
'2019_12_31_16_55_41.38-Isd'
'2020_1_1_12_7_5.13-Isd'
};
>> 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)
Notes:
  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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by