How do I loop round and upload a different file name each time using csvread?

5 visualizaciones (últimos 30 días)
I have to load in a set number of CSV files and do some analysis on them. I think I have to use num2str but I cant get it working. The file names are called GroupC01, GroupC02, ...., GroupCn. I realise once I go over 10 ill have to change the upload to change both units rather than just the one, I'm planning on putting a new for loop in for when i goes over 10. Any ideas on how to upload the files in a loop? Im also wondering if theres a way so I don't have to use another for loop after the file number goes over 10? Ive pasted my code below, any ideas would be much appreciated as I'm pretty new to this software!
for i=1:setnumber
data = csvread(['groupC0'num2str(i)'.CSV'],6,0);

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Abr. de 2013

Más respuestas (1)

John Atkinson
John Atkinson el 23 de Abr. de 2013
You can use"dir" to do something a long the lines of:
listing = dir;
for iPart=3:length(listing);
file = listing(iPart).name
data = csvread(file,6,0);
RUNFUNCTION
end
Assuming that all the files are in the current directory. This will upload each of them and run the specified function (or code).

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by