フィルターのクリア

How to work with categorical or "cell" variables within a table?

13 ビュー (過去 30 日間)
greenyellow22
greenyellow22 2022 年 5 月 11 日
回答済み: Star Strider 2022 年 5 月 11 日
Hello! I am new in Matlab so this might be a basic question but I hope that you can help me anyway! :)
I loaded some gaming data as a table in matlab which contains columns such as "Date", "Time", and "Status" such as "Game is loading..." or "life point collected". When I asked for the class of data, each variable was labelled as being a "cell" type.
RandomNo Date Time Status
__________ ______________ ________________ _______________________________________________________________
1.345e+12 {'10/04/2021'} {'17:57:55:890'} {'Saving successful.'}
1.674e+12 {'10/04/2021'} {'17:57:55:890'} {'New Game File created successfully.'}
...
So my question is: how can I convert the variables in a way that I can work with them? For example, to calculate the min or max Date/Time, I would first convert both cell variables into datetime but I only got error messages.
>> time_stamps = datetime(gamingdata{:,3}, 'InputFormat', 'HH:mm:ss.SSS');
Error using datetime
Unable to convert the text to datetime using the format 'HH:mm:ss.SSS'.
OR
>> time_stamps = datetime(gamingdata{:,Time}, 'InputFormat', 'HH:mm:ss.SSS');
'Time' requires Embedded Coder.
Thanks in advance!
  2 件のコメント
KSSV
KSSV 2022 年 5 月 11 日
It would be better to show us your data and tell us your expectations.
greenyellow22
greenyellow22 2022 年 5 月 11 日
I did above

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

採用された回答

Star Strider
Star Strider 2022 年 5 月 11 日
Converting the ‘Date’ and ‘Time’ variables to datetime arrays is straightforward, however it is not obvious.
Try this —
T1 = table(rand(2,1)*1E12, [{'10/04/2021'}; {'10/04/2021'}], [{'17:57:55:890'}; {'17:57:55:890'}],[{'Saving'};{'Saving Successful'}], 'VariableNames',{'RandomNr','Date','Time','Status'})
T1 = 2×4 table
RandomNr Date Time Status __________ ______________ ________________ _____________________ 8.6947e+11 {'10/04/2021'} {'17:57:55:890'} {'Saving' } 5.6831e+11 {'10/04/2021'} {'17:57:55:890'} {'Saving Successful'}
T1.DateTime = datetime(T1.Date,'InputFormat','dd/MM/yyyy') + timeofday(datetime(T1.Time,'InputFormat','HH:mm:ss:SSS'))
T1 = 2×5 table
RandomNr Date Time Status DateTime __________ ______________ ________________ _____________________ ____________________ 8.6947e+11 {'10/04/2021'} {'17:57:55:890'} {'Saving' } 10-Apr-2021 17:57:55 5.6831e+11 {'10/04/2021'} {'17:57:55:890'} {'Saving Successful'} 10-Apr-2021 17:57:55
T1 = removevars(T1,{'Date','Time'})
T1 = 2×3 table
RandomNr Status DateTime __________ _____________________ ____________________ 8.6947e+11 {'Saving' } 10-Apr-2021 17:57:55 5.6831e+11 {'Saving Successful'} 10-Apr-2021 17:57:55
T1 = T1(:,[1 3 2])
T1 = 2×3 table
RandomNr DateTime Status __________ ____________________ _____________________ 8.6947e+11 10-Apr-2021 17:57:55 {'Saving' } 5.6831e+11 10-Apr-2021 17:57:55 {'Saving Successful'}
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStrategy & Logic についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by