Merge 864 single column text files and 60,000 rows in single file. How to get a matrix with 60000 rows and 864 column

1 visualizzazione (ultimi 30 giorni)

I have 864 single column text files with 60,000 row in single text file.i would like to get a matrix with 60000 rows and 864 columns. Please help me

  3 Commenti

Accedi per commentare.

Risposta accettata

dpb
dpb il 9 Ago 2022
Modificato: dpb il 9 Ago 2022
It would be simpler if you had named the files so they would sort lexically as C001, C002, ... etc., but it's still not too bad...
N=864; % the number files -- better/more general would be to use dir() and count number returned
L=60000; % length of each -- better/more general would be to read first and determine its length
M(L,N)0; % preallocate the output array to those sizes
for i=1:N
fname=char("C"+i+.txt);
M(:,i)=readmatrix(fname);
end
If the filenames were in proper normalized format, I'd be inclined to use the OS to copy and concatenate all into one long file, then read and reshape the resulting long vector instead of the loop...
  5 Commenti
dpb
dpb il 11 Ago 2022
You can type as easily as I ... you've got to put at least SOME effort into solving your own problems rather than relying on being spoon-fed.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by