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!