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

3 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 12 Sep 2022
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

Sign in to comment.

Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!