필터 지우기
필터 지우기

how to average multiple folders with multiple files. I am attaching three folders with two files each. I need a help to find an average of two files from three folders. My code is showing an error"Dot indexing is not supported for variables "

조회 수: 2 (최근 30일)
close all
clear all
D = 'D:\filename\';
S = dir(fullfile(D,'*'));
N = setdiff({S([S.isdir]).name},{'.','..'}); % list of subfolders of D.
for ii = 1:numel(N)
T = dir(fullfile(D,N{ii},'*')); % improve by specifying the file extension.
C = {T(~[T.isdir]).name}; % files in subfolder.
for jj = 1:numel(C)
F = fullfile(D,N{ii},C{jj})
fprintf('test%s\n',F);
S(ii).data = F(:);
end
end
Y = cat(3,S(:))%this line is wrong
out = mean(Y,3)
  댓글 수: 3
MS
MS 2020년 3월 30일
Thanks. I need two files(test_001.txt, test_002,txt) from all three folders(out of six files) finally. let me know if you need further clarifications.
MS
MS 2020년 3월 30일
code through N(here 3 folders) different folders with M(two files here) different.txt files(text​001.txt...​..text002.​txt) with (O rows and P columns). and find the average(te​xt001.txt.​....text002.txt)of M different files from the N folders.

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 30일
Create a script in the same directory where you have folders T1, T2, and T3. Then paste the following code in that script and run it
files = dir('**/*.txt');
data = cell(1, numel(files));
for i=1:numel(files)
filename = fullfile(files(i).folder, files(i).name);
data{i} = readmatrix(filename);
end
M = cat(3, data{:});
average_val = mean(M, 3);
  댓글 수: 22

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by