How do I assign different variable names for different files?

Hi! I have 10 csv files (100*10 size) in one directory. I want read all the files and convert them to tables. I want to assign different variable name for each of the table. For example: data1= file1, data2=file2 and so on. How do I do that? I am a hard time creating dynamic variables like 'data1' in a loop to assign the file data to them. Any help will be much appreciated!

Respuestas (1)

Something like this should work. It would be better to place all the files into a single matrix and use indexing.
for i=1:10
a=sprintf('file%d.csv',i);
eval(['data' num2str(i) '= readmatrix(a);']);
end

1 comentario

"It would be better to place all the files into a single matrix and use indexing."
Which is also exactly what the MATLAB documentation shows:

Iniciar sesión para comentar.

Categorías

Más información sobre Reporting and Database Access en Centro de ayuda y File Exchange.

Productos

Versión

R2022b

Preguntada:

el 25 de Oct. de 2022

Comentada:

el 30 de Oct. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by