Extract a single datetime from a cell array of datetimes

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Voss
Voss il 6 Ago 2023
Modificato: Voss il 6 Ago 2023

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)});

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by