フィルターのクリア

How to loop through N different folders with M different.txt files(text​001.txt...​..text010.​txt) with (O rows and P columns). and plot the average(te​xt001.txt.​....text01​0.txt)of M different figures from the N folders.

2 ビュー (過去 30 日間)
MS
MS 2020 年 3 月 15 日
回答済み: MS 2020 年 3 月 16 日
close all
clear all
D = 'D:\dataprocessing\';
S = dir(fullfile(D,'*'));
N = setdiff({S([S.isdir]).name},{'.','..'}); % list of subfolders of D.
sums = [];
counts = [];
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
X = vertcat(S.data);
avgArrivalDelay = sum(sums)/sum(counts)
  2 件のコメント
Rik
Rik 2020 年 3 月 15 日
Would the data fit in your memory all at once if you read all data and then did the processing?
MS
MS 2020 年 3 月 15 日
yes. it will fit in my memory. Please modify the code for average the files and plot it.

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2020 年 3 月 15 日
Try this. Adapt as needed:
% Get a list of all txt files in the current folder, or subfolders of it.
fds = fileDatastore('*.txt', 'ReadFcn', @importdata)
fullFileNames = fds.Files
numFiles = length(fullFileNames)
% Loop over all files reading them in and plotting them.
for k = 1 : numFiles
fprintf('Now reading file %s\n', fullFileNames{k});
% Now have code to read in the data...
% Now code to plot the data...
end
  4 件のコメント
Image Analyst
Image Analyst 2020 年 3 月 15 日
Attach at least two of your data files so I can do it for you. Use the paper clip icon.
Image Analyst
Image Analyst 2020 年 3 月 15 日
I'll just check back tomorrow.

サインインしてコメントする。


MS
MS 2020 年 3 月 16 日
Thanks. i am attaching the THREE test from one folder.

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by