Load one file from many different folders

1 次查看(过去 30 天)
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?

采纳的回答

Voss
Voss 2024-3-6
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 个)

类别

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