Table of Tables or cell of Tables

152 views (last 30 days)
Hi,
I am preforming machine learning on 13 channels of data and am currently at the feature extraction stage. I have created 13 seperate tables and now which to bring these together into one variable.
I had been trying to create a 1*13 table in which each table element was another table, however I cannot get this to work. I have been able to create a 1*13 cell with each cell element being a table instead. My question is this, is there any benifit to using a tables within cells over tables within tables and vice versa. I will also include some code below, I would like to know how to also make this work for tables within tables too for furture use!
filesTable = array2table(fileNames); % Generate file names to identify each entry
sTruthBuffer = sTruthBuffer';
truthTable = array2table(sTruthBuffer); % Generate ground (clinical) truth
channels = cell(13,1); % generate empty cell for later
for i = 1:13 % For each of the 13 channels
actTable = rows2vars(array2table(act(:,:,i))); % act(ivity) is a 1*2538*13 double
actTable = removevars(actTable,'OriginalVariableNames'); % remove the orignal variale names as junk
actTable.Properties.VariableNames = {'Activity'} % Rename column as something sensible
mobTable = rows2vars(array2table(mob(:,:,i))) % mob(ility) is a 1*2538*13 double
mobTable = removevars( mobTable,'OriginalVariableNames');
mobTable.Properties.VariableNames = {'Mobility'}
complxTable = rows2vars(array2table(complx(:,:,i))) % complx(ity) is a 1*2538*13 double
complxTable = removevars(complxTable,'OriginalVariableNames');
complxTable.Properties.VariableNames = {'Complexity'}
channel = [filesTable,actTable,mobTable,complxTable,truthTable]; % Concatinate all the tables into one table 'channel'
channels{i} = channel ; % for each channel write the generated table 'channel' into a cell array called 'channels',
% this is okay but I think a nested table would be easier to work with?
end

Accepted Answer

Seth Furman
Seth Furman on 12 Nov 2021
Hi Christopher,
I had been trying to create a 1*13 table in which each table element was another table, however I cannot get this to work.
  • What is your reason for wanting to store these 13 tables in a single 1x13 table? Are you doing this because you want to have a label for each table?
  • Where are you getting stuck? Is the issue that the tables are different heights? Table variables must have the same height, but one way to get around this is to put the tables in cell arrays, e.g.
t1 = table([1;2;3]);
t2 = table([1;2]);
table({t1}, {t2}, 'VariableNames', ["MyLabel1", "MyLabel2"])
ans = 1×2 table
MyLabel1 MyLabel2 ___________ ___________ {3×1 table} {2×1 table}
It's also worth mentioning that you can store additional metadata in the UserData property of each table, e.g.
t1.Properties.UserData = "MyLabel1";
t2.Properties.UserData = "MyLabel2";
{t1, t2}
ans = 1×2 cell array
{3×1 table} {2×1 table}
  5 Comments
Christopher McCausland
Christopher McCausland on 20 Nov 2021
Hi Seth,
This helped me massively thank you! I went down the approach of (2) storing multiable channels as sub tables, this worked for me as tables are accepted by MATLAB ML tools and what I had failed to realise is that multiple channels should be fed in side by side for ML rather than independetly. I have some initial results from my ML which are as I would expect, now I just have to improve these with additional channel and feature selection. Thank you again for all you help!!!
Christopher

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!