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

2 views (last 30 days)
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);

Accepted Answer

Walter Roberson
Walter Roberson on 23 Apr 2013

More Answers (1)

John Atkinson
John Atkinson on 23 Apr 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).

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!