Sequencing data in the loop (*.CSV files)

2 visualizaciones (últimos 30 días)
Abdul Hannan
Abdul Hannan el 12 de Mzo. de 2024
Comentada: Stephen23 el 12 de Mzo. de 2024
Hi,
the sequence of Output is not ok. How can I keep the data in sequnce. Kindly advise what I am missing ?
*.CSV files are like "D1.CSV, D2.CSV, D3.CSV............................D35.CSV"
The output file is not following this sequence.
files = dir('Data\*.CSV') ;
%files = natsortfiles({files.name}); %natsortfiles external Add In
N = length(files) ;
Output = cell(N,1) ;
for i = 1:N
Output{i} = readmatrix(files(i).name) ;
end
Advise please.

Respuesta aceptada

Stephen23
Stephen23 el 12 de Mzo. de 2024
Movida: Stephen23 el 12 de Mzo. de 2024
"How can I keep the data in sequnce."
Either use sufficient leading zeros in the filenames OR sort the filenames alphanumerically.
Kindly advise what I am missing ?"
files = dir('Data\*.CSV');
files = natsortfiles(files); % <- this
  2 comentarios
Abdul Hannan
Abdul Hannan el 12 de Mzo. de 2024
Movida: Stephen23 el 12 de Mzo. de 2024
Yes, thankyou for correction. I was applying 'natsortfiles' unnecessarily using '.name'. Issue resolved thanks.
Stephen23
Stephen23 el 12 de Mzo. de 2024
@Abdul Hannan: I hope that it helped. Please remember to click the accept button!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by