datetime reading out NaT for all rows of structure except last in loop

조회 수: 3 (최근 30일)
Poison Idea fan
Poison Idea fan 2022년 9월 12일
댓글: Poison Idea fan 2022년 9월 12일
I am trying to get durations of a reoccurring event in a timetable by taking the datestring of a file and removing a duration from the timetable. When I try to convert the datestrings in a structure, all but the last row is output as NaT. I've tried setting the input format as well. For some reason I got it to work once but when I added it to my function this problem started happening.
I've pasted the for loop below and in this editor it seems to be working but I'm confused as to why it doesn't work in my function.
load sweep_data.mat
for n = 1:length(sweep_struct)
sweep_datetime(n,1) = datetime(sweep_struct(n).date);
end
  댓글 수: 3
Stephen23
Stephen23 2022년 9월 12일
Avoiding the loop is easy:
S = load('sweep_data.mat');
D = datetime({S.sweep_struct.date}).'
D = 323×1 datetime array
13-Jun-2022 16:36:35 13-Jun-2022 20:50:07 13-Jun-2022 21:20:08 13-Jun-2022 21:50:09 13-Jun-2022 22:20:09 13-Jun-2022 22:50:10 13-Jun-2022 23:20:10 13-Jun-2022 23:50:10 14-Jun-2022 00:20:11 14-Jun-2022 00:50:11 14-Jun-2022 01:20:11 13-Jun-2022 16:50:03 14-Jun-2022 01:50:13 14-Jun-2022 02:20:13 14-Jun-2022 02:50:13 14-Jun-2022 03:20:13 14-Jun-2022 03:50:14 14-Jun-2022 04:20:14 14-Jun-2022 04:50:15 14-Jun-2022 05:20:15 14-Jun-2022 05:50:16 14-Jun-2022 06:20:16 13-Jun-2022 17:20:04 14-Jun-2022 06:50:17 14-Jun-2022 07:20:17 14-Jun-2022 07:50:18 14-Jun-2022 08:20:18 14-Jun-2022 08:50:19 14-Jun-2022 09:20:19 14-Jun-2022 09:50:20

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by