accessing a .csv file with a certain name in a folder and calculating its average, but doing this for several folders in subfolders.
1 次查看(过去 30 天)
显示 更早的评论
I have a main folder
\MainFolder\
within this folder are individual folders for each participant (32)
100514, 120414, .....310513 [all six digit ids]
participant = 1:size(nameFolds,1)
within each participant folder, there is another folder called Detection results
In this folder there are 40 folders '1_1', '1_2', ....'1_40'.
Within each of these are .csv files. I would like to take the file with name ending in
1_1_FixationDuration.csv
1_1_saccadeAmplitude.csv
1_1_saccadeDuration.csv
each of these contain a list of numbers and I would like to output the number of items and their average in a different csv file.
The code that has worked for me for one folder is
folder = 'D:\.....\MainFolder\100514\DetectionResults\1_1\';
csvFiles = dir(fullfile(folder, '*.csv')); % Using absolute path names
numfiles = length(csvFiles);
average = zeros(1, numfiles);
for k = 1:numfiles
M = csvread(fullfile(folder, csvFiles(k).name));
average(k) = mean(M(:,1));
end
csvwrite(fullfile(folder_out, 'output.csv'), average);
but i would like this to loop through the several folders and read those files ending in [1_1_FixationDuration.csv, 1_1_saccadeAmplitude.csv
1_1_saccadeDuration.csv] in particular, not any other .csv that may exist.
0 个评论
回答(1 个)
DrZoidberg
2020-1-28
maybe this link helps you: https://de.mathworks.com/help/matlab/datastore.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!