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?
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!