How to work with categorical or "cell" variables within a table?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
greenyellow22
il 11 Mag 2022
Risposto: Star Strider
il 11 Mag 2022
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 Commenti
Risposta accettata
Star Strider
il 11 Mag 2022
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.DateTime = datetime(T1.Date,'InputFormat','dd/MM/yyyy') + timeofday(datetime(T1.Time,'InputFormat','HH:mm:ss:SSS'))
T1 = removevars(T1,{'Date','Time'})
T1 = T1(:,[1 3 2])
.
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!