How do I loop round and upload a different file name each time using csvread?
5 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
更多回答(1 个)
John Atkinson
2013-4-23
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).
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!