Extract a single datetime from a cell array of datetimes

2 次查看(过去 30 天)
Hello!
Data sent to me has, among other things, a cell array of datetimes, e.g.
K>> input_struc.event_date_time
ans =
2058×1 cell array
{[23-Sep-2020 14:13:54]}
{[23-Sep-2020 14:24:43]}
{[23-Sep-2020 15:31:41]}
{[23-Sep-2020 15:56:37]}
...
I have another cell array of numbers that have a CR in them.
If I run using this code, it works (since I have just defined the starting_event_date as char:
starting_event_date = 'junko';
%starting_event_date = datestr(input_struc.event_date_time(ident(1)));
starting_event_serial_number = str2double(input_struc.serial_number(ident(1)));
set(handles.current_sn_and_date_text,'String',['SN ',num2str(starting_event_serial_number),' at ',starting_event_date]);
However, if I decomment the starting_event_date line, or try some other way to get the datetime out of the cell, it doesn't work.
Thoughts?
Thanks!
Doug Anderson

采纳的回答

Voss
Voss 2023-8-6
编辑:Voss 2023-8-6

Use curly braces to access the contents of a cell array, and it is recommended to use char() instead of datestr() to convert a datetime to text.

starting_event_date = char(input_struc.event_date_time{ident(1)});

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by