Using horzcat in a loop for combining large number of files

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by