How do I load in multiple datasets from multiple folders?

I have run into a problem with my code where I need to load multiple .DAT files from multiple files that are deeply embeded in one another. For example, I have a main folder I need to access that has multiple folders inside of it, then I need to access this sub file which has multiple folders in it. Following this path is where the .dat files are located: 3D\amplitude\0 Amps\Static_Hysteresis however there are multiple "# Amps" files I need to access and get the .dat files out of all with the static hystresis file inside. I have attached a code to show how far I've gotten, however I am relatively new to matlab and therefore inexperienced.

답변 (1개)

Voss
Voss 2024년 4월 10일
You can use * and/or ** wildcards in dir.
Example:
folder = 'absolute\or\relative\path\to\folder\3D\amplitude';
dir_str = fullfile(folder,'*Amps','Static_Hysteresis','*.dat')
dir_str = 'absolute\or\relative\path\to\folder\3D\amplitude/*Amps/Static_Hysteresis/*.dat'
Then dir(dir_str) will return information about any .dat file located in a folder called "Static_Hysteresis", which is located in a folder whose name ends with "Amps", which is located directly in "\3D\amplitude". This seems to be what you are trying to do.

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2024년 4월 10일

답변:

2024년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by