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!