Effacer les filtres
Effacer les filtres

Extract a single datetime from a cell array of datetimes

2 vues (au cours des 30 derniers jours)
Douglas Anderson
Douglas Anderson le 6 Août 2023
Commenté : Douglas Anderson le 6 Août 2023
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

Réponse acceptée

Voss
Voss le 6 Août 2023
Modifié(e) : Voss le 6 Août 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 commentaire
Douglas Anderson
Douglas Anderson le 6 Août 2023
Thank you! Cells have always been a bit of a mystery to me, much appreciated!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by