Read multiple csv of similar names

Hello,
Let's say I have multiple csv files that are named 'valuesx.csv' where x is a number between 0-99, so I have 100 csv files with similar names.
Is there a way to read all of the files into Matlab without having to use 'readtable' 100 times for each of the files. I was thinking that I could use a for-loop (or something similar) to read all of the files, but my problem is that I don't know how to make it read multiple files.
I was thinking something like this:
for x = 0:99
readtable(valuesx);
end
I know that this code doesn't work, but I was thinking something like this.
Is there a way to make such a code or do I need to read each file separately with 'readtable'?

 Respuesta aceptada

the cyclist
the cyclist el 26 de Sept. de 2023
Editada: the cyclist el 26 de Sept. de 2023
Something like this
for x = 0:99
filename = sprintf("values%d.csv",x)
tbl{x+1} = readtable(filename);
end
This will store each file in one cell of a cell array. Note that I had to offset the number of the cells, because MATLAB does not have 0-based indexing.

3 comentarios

Dyuman Joshi
Dyuman Joshi el 26 de Sept. de 2023
It would be better to add the format of the file in the sprintf() call as well.
the cyclist
the cyclist el 26 de Sept. de 2023
I think you may have composed this comment in the one minute in between my initial post and my edit where I fixed that oversight. :-)
Dyuman Joshi
Dyuman Joshi el 26 de Sept. de 2023
Haha, I see.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Productos

Versión

R2023a

Preguntada:

el 26 de Sept. de 2023

Comentada:

el 26 de Sept. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by