how to concatenate two tables efficiently

9 ビュー (過去 30 日間)
Salma fathi
Salma fathi 2022 年 7 月 6 日
回答済み: Campion Loong 2022 年 7 月 21 日
I am trying to read a huge amount of files, each file would have data stored in a atable in it, after reading the files we would like o put all the tables from the files into one big table, to concatenate the table i am using the follwoing lines. They work just fine but the issue is when the table size get much bigger the loop will be running relatively slow and unefficintely. Is there any more efficient way to do it?
if ifile==3
EDPAll=EDPT(:,[1,6:7]);
else
EDPAll=[EDPAll;EDPT(:,[1,6:7])];
end

回答 (2 件)

Jonas
Jonas 2022 年 7 月 6 日
編集済み: Jonas 2022 年 7 月 6 日
before concatenation you can go trough all tables and add up the number of rows. Then preallocate the table using three columns and the number of rows you found. Then assign the values explicitly using indexing, e.g.
% -> preallocate here the table in suitable size e.g. EDPAll <-
currFirstIdx=1;
for nr=1:numOfTables
% -> here, retrieve table number nr, e.g. EDPT <-
EDPAll(currFirstIdx:currFirstIdx+height(EDPT)-1,:)=EDPT;
currFirstIdx=currFirstIdx+height(EDPT);
end

Campion Loong
Campion Loong 2022 年 7 月 21 日
"I am trying to read a huge amount of files, each file would have data stored in a atable in it"
Have you tried using Datastore to manage this workflow? Use tabularTextDatastore if all your files are text in tabular data format. You can use the "SelectedVariableNames" Name/Value pair to read in only the variables you can about (i.e. rather than read everything and then only select [1,6:7]), then read everything with readall() or read only up to the size (i.e. ReadSize) you are interested in

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by