Using horzcat in a loop for combining large number of files

2 ビュー (過去 30 日間)
Sagar
Sagar 2017 年 7 月 27 日
編集済み: Constance Woodman 2017 年 7 月 27 日
hi, I need to combine 100 matrices horizontally using horzcat. I have a matrix named 'data' of size 20*30*100 in which 100 represents number of data granules for a day. I want to do the following: data_all = horzcat(data(:, :, 1), data(:, :, 2), data(:, :, 3) ................... upto 100). I want to do this in a loop since it is tedious to write all matrices from 1 to 100. Could you please suggest a quick way?
  1 件のコメント
Constance Woodman
Constance Woodman 2017 年 7 月 27 日
編集済み: Constance Woodman 2017 年 7 月 27 日
I'm not super elegant at this but would think you would want to do it in one command rather than adding a column, then adding a column, etc., as a loop. I have been working with huge datasets and it can crash matlab on my older work machine when I make Matlab do extra work.
Maybe rather than horizontally concatenating in a loop, you could create a loop that writes the list for concatenation, then just insert the list?
I'm just sort of pseudo coding this out...
% initilize
x = total number columns
counter= 1
hugeFlippingString = empty string
% run loop
Loop until counter = total number of columns
append text to hugeFlippingString: "columnOrFileName", counter, ","
counter increment by 1
End loop
%Concatenate
giantMatrix = horzcat(hugeFlippingString)
% which actually does this: giantMatrix = horzcat(col1,col2, ... col100)

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

採用された回答

James Tursa
James Tursa 2017 年 7 月 27 日
編集済み: James Tursa 2017 年 7 月 27 日
data_all= reshape(data,size(data,1),[]);
Or, if you needed to vertcat them instead, then you could use
result = reshape(permute(data,[2 1 3]),size(data,2),[])';

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by