Retrieve data from several structures and folders

조회 수: 5 (최근 30일)
Isma_gp
Isma_gp 2019년 1월 7일
편집: Stephen23 2019년 1월 8일
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
Stephen23
Stephen23 2019년 1월 7일
편집: Stephen23 2019년 1월 8일
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:

댓글을 달려면 로그인하십시오.

답변 (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에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by