MATLAB: Using horzcat in a loop for combining large number of files

horzcat

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?

Best Answer

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),[])';