How to read files in ascending order based on the maximum value of the file from subfolders?
2 views (last 30 days)
Show older comments
Sateesh Kandukuri
on 19 Nov 2022
Commented: Sateesh Kandukuri
on 20 Nov 2022
I have table.txt files in the subfolders of a directory. First I want to find the maximum value of a particular coulmn of the table.txt file. Then, I want to read these files in an ascening order based on these values. I can read the files. But unable to sort the files in the way I want to process the data further. Can somebody help me out?
allTables = dir('**/table.txt');
tablemax =zeros();
for ii = 1:numel(allTables)
thisFolder = allTables(ii).folder;
inFile = fullfile(thisFolder, allTables(ii).name);
A = readmatrix(inFile);
% do stuff ...
I=max(A(:,13));
tablemax(1:length(I),ii)=I;
end
iinew=sort(tablemax);
0 Comments
Accepted Answer
Stephen23
on 19 Nov 2022
Edited: Stephen23
on 20 Nov 2022
S = dir('**/table.txt');
for k = 1:numel(S)
F = fullfile(S(k).folder, S(k).name);
A = readmatrix(F);
% do stuff ...
I = max(A(:,13));
S(k).max = I;
end
[~,X] = sort([S.max]);
S = S(X)
3 Comments
Stephen23
on 20 Nov 2022
Edited: Stephen23
on 20 Nov 2022
@Sateesh Kandukuri: fixed now, the line must be:
[~,X] = sort([S.max]);
More Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!