Retrieve data from several structures and folders

2 次查看(过去 30 天)
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 个)

Bob Thompson
Bob Thompson 2019-1-7
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.

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by