How do I loop round and upload a different file name each time using csvread?
조회 수: 6 (최근 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!