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.

Respuestas (1)

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.

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Productos

Versión

R2018b

Preguntada:

el 10 de Abr. de 2024

Respondida:

el 10 de Abr. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by