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 visualización (últimos 30 días)

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 comentarios

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 9 de Ag. de 2022
Editada: dpb el 9 de Ag. de 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 comentarios
dpb
dpb el 11 de Ag. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by