Extract a single datetime from a cell array of datetimes

2 ビュー (過去 30 日間)
Douglas Anderson
Douglas Anderson 2023 年 8 月 6 日
コメント済み: Douglas Anderson 2023 年 8 月 6 日
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)});
  1 件のコメント
Douglas Anderson
Douglas Anderson 2023 年 8 月 6 日
Thank you! Cells have always been a bit of a mystery to me, much appreciated!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by