Load one file from many different folders
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have an huge amount of data. I want to load into matlab.
The data is placed in many different folders. But each with one .dat file.
Are there a clever way to do this?
P = 'C:\UndrianedMon\triax_hypoplasticityta70-print-out';
S = dir(fullfile(P,'EALL_element_1.dat'));
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
T = importdata(F).data;
end
This code works for me. But is not that smart, as i need to copy it many times to get the .dat files I need.
Can anyone help me?
0 Kommentare
Akzeptierte Antwort
Voss
am 6 Mär. 2024
You can use wildcard characters in dir to find files in many different folders.
Examples:
% some directory that contains all folders containing your dat files:
P = 'C:\UndrainedMon';
% (1) this gets info about all .dat files in any folder in P
% (i.e., only one level down from P):
S = dir(fullfile(P,'*','*.dat'));
% (2) this gets info about all .dat files in any folder anywhere in P
% (i.e., any number of levels down from P):
S = dir(fullfile(P,'**','*.dat'));
0 Kommentare
Weitere Antworten (0)
Siehe auch
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!