Concatenating multiple tables in a cell array

Hello Everyone, I have a cell array with hundreds of tables in it, It's a 1165x1 cell array. The first 499 are empty cells but the rest have tables in them. from T{500} to T{end}
Most of the tables are 20x153 tables but some of them have different amount of columns (I have identified about 10 out of the 500) which have columns ranging from 130 to 157 columns. Is there a way I could concatenate vertically all the tables in the cell array with 20x153 dimensions ignoring these outliers?
Thank you.

2 件のコメント

Walter Roberson
Walter Roberson 2021 年 7 月 19 日
The entries that have fewer than 153 columns: you want to ignore those entries completely, right?
The entries that have more than 153 columns: do you want to ignore those entries completely, or do you want the first 153 columns of them to be used?
Daniel Abraham
Daniel Abraham 2021 年 7 月 19 日
Well I was actually looking for an easy way out haha,I think I’d prefer the second option if it’s possible.

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

 採用された回答

Walter Roberson
Walter Roberson 2021 年 7 月 19 日

0 投票

mask = cellfun(@(c) size(c,2) == 153, T);
Tfull = vertcat(T{mask});

8 件のコメント

Daniel Abraham
Daniel Abraham 2021 年 7 月 19 日
It helps a lot, thanks so much
Peter Perkins
Peter Perkins 2021 年 7 月 27 日
A slight modification should allow you to keep the first 153 variables of tables that have more variables than that:
mask = cellfun(@(c) size(c,2) >= 153, T);
T2 = cellfun(@(tbl) tbl(:,1:153), T(mask), 'UniformOutput',false);
Tfull = vertcat(T2{:});
Walter Roberson
Walter Roberson 2021 年 7 月 27 日
Yes, that should work well.
Daniel Abraham
Daniel Abraham 2021 年 7 月 27 日
Okay, I'll try it and see. Thank you for your input @Peter Perkins, Hey, @Walter Roberson, I tried this code about 5 times but on my computer, it takes about 7hrs on average to import about 700 xml files. What do you think from your experience, could it be much faster or is that how long it should take that specific amount of files running this code on an average Mac. Would like to know your thoughts.
Walter Roberson
Walter Roberson 2021 年 7 月 27 日
What code are you using to import the XML files?
Are the XML files stored on hard drive or on SSD?
Daniel Abraham
Daniel Abraham 2021 年 7 月 27 日
okay this the code. The xml files are stored on a one drive. But I think I get a notofication that MATLAB downloads to my drive which is an SSD when starting to run the code.
%% Import xml files, well about half of it
xmlFiles = dir('*.xml');
N = length(xmlFiles);
T = cell(N,1);
for i = 500:N %The reason I chose 500 is because importing from 1 never completes
% There are about 1,200 files in all
T{i} = readtable(xmlFiles(i).name) ;
end
celldisp(T) % to display activity in command window
%% Concatenating all tables
mask = cellfun(@(c) size(c,2) == 153, T);
T_merged = vertcat(T{mask});
Walter Roberson
Walter Roberson 2021 年 7 月 27 日
That code does not download from OneDrive to local disk, but if possible you would really rather read from local disk than from OneDrive. The performance loss for reading from OneDrive can be substantial. Even just starting by copying the files to local drive can improve performance a lot.
Daniel Abraham
Daniel Abraham 2021 年 7 月 27 日
I see, thanks a lot, I appreciate your suggestions

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by