Using horzcat in a loop for combining large number of files

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Constance Woodman
Constance Woodman il 27 Lug 2017
Modificato: Constance Woodman il 27 Lug 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)

Accedi per commentare.

Risposta accettata

James Tursa
James Tursa il 27 Lug 2017
Modificato: James Tursa il 27 Lug 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),[])';

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by