Extract a single datetime from a cell array of datetimes

1 visualización (últimos 30 días)
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

Respuesta aceptada

Voss
Voss el 6 de Ag. de 2023
Editada: Voss el 6 de Ag. de 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)});
  1 comentario
Douglas Anderson
Douglas Anderson el 6 de Ag. de 2023
Thank you! Cells have always been a bit of a mystery to me, much appreciated!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by