MATLAB: How to separate date and time into two tables

date and timeseparate

Hi, i am new to Matlab. I have a problem with separating imported data of date and time over the year (8760 values) into two tables. Imported data looks like this. Its a cell of data in one column and i need to separate it to date in one table and time in second table.
'01/01 01:00:00'
'01/01 02:00:00'
'01/01 03:00:00'
.
.
'12/31 22:00:00'
'12/31 23:00:00'
'12/31 24:00:00'
Thank you for any help.

Best Answer

Hi,
I hope the following piece of code may help you a little bit. I am not sure if the "table" in your question means the build-in func table in MATLAB. It is added at the end in case. The performance can be improved by using cellfun. As you are new to MATLAB, I guess the for loop structure may be more straightforward.
%%Params
input_cell={'01/01 01:00:00';
'01/01 02:00:00';
'01/01 03:00:00';
'12/31 22:00:00';
'12/31 23:00:00';
'12/31 24:00:00'};
%%Process
num_data_rows=numel(input_cell);
table_date_cell=cell(num_data_rows,1);
table_time_cell=table_date_cell;
for i=1:num_data_rows
cur_data_row=input_cell{i};
cur_date_time_cell=strsplit(cur_data_row);
table_date_cell(i)=cur_date_time_cell(1);
table_time_cell(i)=cur_date_time_cell(2);
end
%%Display
table(table_date_cell,'VariableNames',{'Date'})
table(table_time_cell,'VariableNames',{'Time'})