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 日

0 投票

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