How can I load a sequence of csv files and process them by subsets
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sérgio Timóteo
am 18 Mär. 2016
Bearbeitet: Sérgio Timóteo
am 23 Mär. 2016
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 Kommentar
Jan
am 19 Mär. 2016
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?
Akzeptierte Antwort
Dave Behera
am 22 Mär. 2016
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 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!