Most efficient way to vertically concatenate numeric data?
    3 ビュー (過去 30 日間)
  
       古いコメントを表示
    
In the profiled output picture below, mergedDataPerRank is a cell array storing 53 double matrices with size (6300, 33). Using vertcat, it takes approx. 0.5 seconds (20 calls) to vertically concatenate the data. Is there a more efficient way to do this or is 0.5 seconds already fairly good? 

4 件のコメント
  Konstantin
 2025 年 4 月 3 日
				
      編集済み: Konstantin
 2025 年 4 月 3 日
  
			But what is "Merge_filesAcrossRanks"? It looks like it is some your own custom function to read a lot of files in a given directory. If it is so (and if the size of all tables is quaranteed a priori), then I would recommend to combine reading and merging: just preallocate the whole final matrix (53*6300 tall, 33 wide), create a "current position (line)" variable, and then read files into this table while advancing the "current position".
  Walter Roberson
      
      
 2025 年 4 月 3 日
				That approach turns out to be slower.
nmat = 53;
nrow = 6300;
ncol = 33;
rng(12345)
tic
C = cell(nmat, 1);
for K = 1 : nmat; C{K} = rand(nrow, ncol); end
R1 = vertcat(C{:});
t1 = toc;
rng(12345);
R2 = zeros(nmat*nrow,ncol);
counter = 1;
for K = 1 : nmat; R2(counter:counter+nrow-1,:) = rand(nrow, ncol); counter = counter + nrow; end
t2 = toc;
format long g
[t1, t2]
回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



