Using horzcat in a loop for combining large number of files

3 visualizaciones (últimos 30 días)
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 comentario
Constance Woodman
Constance Woodman el 27 de Jul. de 2017
Editada: Constance Woodman el 27 de Jul. de 2017
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)

Iniciar sesión para comentar.

Respuesta aceptada

James Tursa
James Tursa el 27 de Jul. de 2017
Editada: James Tursa el 27 de Jul. de 2017
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),[])';

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by