Loop variable for readtable arguments

13 visualizaciones (últimos 30 días)
vauntedmango
vauntedmango el 24 de En. de 2023
Comentada: Stephen23 el 24 de En. de 2023
I am trying to read several tables within the same directory (currently in .txt format). The file names are as follows:
0.0.txt
0.2.txt
0.4.txt
and so on until 2.0.txt
How can I implement the loop feature to tell MATLAB to read all the files starting from 0.0.txt up to 2.0.txt with the value before '.txt' increasing by 0.2 each time?

Respuesta aceptada

KSSV
KSSV el 24 de En. de 2023
txtFiles = dir('*.txt') ;
N = length(txtFiles) ;
for i = 1:N
T = readtable(txtFiles(i).name)
end
  1 comentario
Stephen23
Stephen23 el 24 de En. de 2023
And if you want to keep all of the imported data:
S = dir('*.txt');
for k = 1:numel(S)
S(k).data = readtable(S(k).name);
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by