Retrieve data from several structures and folders

2 vues (au cours des 30 derniers jours)
Isma_gp
Isma_gp le 7 Jan 2019
Modifié(e) : Stephen23 le 8 Jan 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
  1 commentaire
Stephen23
Stephen23 le 7 Jan 2019
Modifié(e) : Stephen23 le 8 Jan 2019
This is a continuation of this question:
@Isma_gp: Use a non-scalar structure:
Then you can use much simpler and more effiicient indexing, rather than messing about with generating fieldnames. You have already been shown how to use non-scalar structures:

Connectez-vous pour commenter.

Réponses (1)

Bob Thompson
Bob Thompson le 7 Jan 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.

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by