Filter löschen
Filter löschen

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 Ansichten (letzte 30 Tage)
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 Kommentare
MS
MS am 30 Mär. 2020
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 am 30 Mär. 2020
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 30 Mär. 2020
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 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations 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!

Translated by