How can I load a sequence of csv files and process them by subsets

조회 수: 1 (최근 30일)
Dear all,
This might be a fairly trivial question, but given that I'm very new to Matlab I've not been able to sort this out by myself.
I've a number of files that I need to process in batches files at a time. The files' name has two different parts: a descriptive part e a numeric part, as in the example below:
a_1.csv; a_2.csv;...; a_n.csv
b_1.csv; b_2.csv;...; b_n.csv
c_1.csv; c_2.csv;...; c_n.csv
...
x_1.csv; x_2.csv;...; x_n.csv
The idea is that at each time I apply a function to a_1 to x_1 files, then a_2 to x_2 files, and so on. After each run I'll get a value out of the function, which will then be stored in a vector of length n. I reckon I should use a for loop to go through all files getting each time all files ending with 1 (or whatever number) and then apply the function, and then again and again. My issue here is that I've not been able to the subseting to run each set of files at a time.
Any help with this would be very much appreciated.
  댓글 수: 1
Jan
Jan 2016년 3월 19일
The question is not clear. What exactly is the problem? What have you tried so far? Is the creation of the file names the problem, or the processing of the files, storing the results or anything else?

댓글을 달려면 로그인하십시오.

채택된 답변

Dave Behera
Dave Behera 2016년 3월 22일
I believe that you are referring to the files a_i.csv-x_i.csv where I ranges from 1 to n, as your 'subsets'.
If that is the case, then you can use a for loop that ranges from 1 to n. Inside each such loop use another for loop to go from files a_i.csv to x_i.csv:
for i= 1:n str = 'abcdefghijklmnopqrstuvwx'; for j = 1:length(str) filename = [str[j] '_' num2str(i) '.csv']; %use csvread to read file and update your vector %your code here end end
  댓글 수: 1
Sérgio Timóteo
Sérgio Timóteo 2016년 3월 23일
편집: Sérgio Timóteo 2016년 3월 23일
That was exactly the situation. Sorry if I didn't explain it well. Anyway, many thanks for this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by