Retrieve data from several structures and folders

2 visualizzazioni (ultimi 30 giorni)
Isma_gp
Isma_gp il 7 Gen 2019
Modificato: Stephen23 il 8 Gen 2019
Hi, I need to extract information from several structures organized in different folders.
The data is organized in folders.
The folders are folder_1, folder_2.....folder_n. Each folder contains a structure called moo_data. Each structure contains several structures (file_1, file_2, file_3...etc). The number of structures within each moo_data structure could be different on each folder.
Each of these structures contains a double (24x20) called response that I need to extract.
I would like to structure the extracted data in the following manner:
Newstructure.folder_1.response
Newstructure.folder_2.response
Can I get some help?
Thanks

Risposte (1)

Bob Thompson
Bob Thompson il 7 Gen 2019
If I'm understanding this correctly, you're looking to dynamically change the variable you're using each time you go through the for loop? I don't know that it's possible to do this directly, and it's generally considered bad practice within MATLAB. I would suggest that you change the layout of your structure to contain a single generic name, and an index.
Newstructure.folder(1).response = ...
This will make looping much more simple, as adjusting an index is much easier within a MATLAB loop.
I think a better option though, assuming all of your files are named the same, would be to use a recursive file locator with the dir() command.
If you are using 2016b or newer, then this can be done using the dir command directly:
filelist = dir(['parent_directory','**','response']);
I'm not absolutely certain that is the exact format, but you can look it up fairly easily with a google search.
If you are not using 2016b or newer, then the file exchange has several recursive file searching codes. Personally, I have used this one, and found it to be adequate for locating files.

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by