Load one file from many different folders

1 visualización (últimos 30 días)
mads skibsted
mads skibsted el 6 de Mzo. de 2024
Respondida: Voss el 6 de Mzo. de 2024
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?

Respuesta aceptada

Voss
Voss el 6 de Mzo. de 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'));

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by