Clear Filters
Clear Filters

How do I split a timetable into smaller timetables based on the data in a column in the timetable?

23 views (last 30 days)
I am splitting up a timetable that contains a datetime column and then a bunch of collumbs of hex code. I want to devide it up in groups based on the data in the fist collumb of hex. The code below works well but I want the outputs to be timetables and they are just tables.
Here is a sample of three rows from the timetable RAW that I am using:
'151-17:28:25.047688' "54E1" "5000" "0000" <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing>
'151-17:28:26.274193' "CC26" "C800" "2F47" "D682" "0000" "0004" "0000" "0020" <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing>
'151-17:28:53.149654' "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000" "0000"
% columnb number 1 is used
G = findgroups(RAW{:, 1});
% Split table based on 1553 status word (column 2)
T_split = splitapply( @(varargin) varargin, RAW , G);
% Allocate empty cell array fo size equal to number of rows in T_Split
subTables = cell(size(T_split, 1));
% Create sub tables
for i = 1:size(T_split, 1)
subTables{i} = table(T_split{i, :}, 'VariableNames', ...
RAW.Properties.VariableNames);
end
R = (subTables{1})
S = (subTables{2})
T = (subTables{3})
V = (subTables{4})
w = (subTables{5})
X = (subTables{6})
Y = (subTables{7})
Z = (subTables{8})

Answers (1)

Samay Sagar
Samay Sagar on 7 Jun 2023
You can use table2timetable function to convert table to timetable. You can refer the docs here.
  2 Comments
Joel
Joel on 7 Jun 2023
Thanks, I understand that but for some reason when I use the code above the output no longer contains the date time column so I cannot convert it to a timetable.

Sign in to comment.

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!