- Do you want the user to be offered a list of folder names, from which they can make a selection?
- Do you want to provide a cell array of folder names, and loop over those names?
- Do you want to use some criteria to automatically select folder names from the complete list of folders?
- etc.
How to get selected folders from multiple folders in a directory?
7 次查看(过去 30 天)
显示 更早的评论
I have multiple folders named as run_0.05, run_0.10, run_0.15..........run_2.50 etc. I would like to select particular 4 folders like run_0.25, run_0.50, run_0.75 and run_1.0. How do I get selected folders from a multiple folders?
4 个评论
Stephen23
2018-10-24
编辑:Stephen23
2018-10-24
"Hope this helps."
Not really, because you did not explain what "automatically select" actually means. Do you want to "automatically select" some of the names based on properties or features of those names, or based on another existing list of parts of those names, or based on what the user selects, or by randomly picking four of the names, or by picking the first four names, or ...? What determines which of those names should be "automatically select"-ed ?
If you do not explain how this "automatic selection" is based on, then you are unlikely to get any useful advice.
"I would like to select particular 4 folders like run_0.25, run_0.50, run_0.75 and run_1.0."
What other names are "like" them? Why not just put those names into a cell array and use them?
采纳的回答
Stephen23
2018-10-24
To randomly select four folder names:
D = 'path of the directory where the folders are';
S = dir(fullfile(D,'*'));
X = [S.isdir] & ~ismember({S.name},{'.','..'});
N = {S(X).name};
Y = randperm(numel(N));
Z = N(Y(1:4))
2 个评论
Stephen23
2018-10-25
"If we want to select specific 6 folders such as run1, run2, run3...run6 Do we need to change N?"
N is a cell array of all of the folder names: how would you want to "change" it?
The actual solution is that you would need to define what you mean by "... select specific 6 folders such as...": first you say that you want "specific" folders (that is easy, just write them in a cell array), then you write "... such as...", which implies that it is not those specific folders that you want, but some folders whose names follow some pattern or have some property (which you have not told us about). So one you define what you mean by "select specific folders", then we can help you with it.
更多回答(1 个)
Image Analyst
2018-10-20
Once you have a cell array with all the folder names in it, use ismember() to find the indexes of the one you want.
[ia, ib] = ismember(desiredFolderName, allFolderNames)
5 个评论
Image Analyst
2018-10-22
Try (untested)
files = [dir('**/run_0.25');...
dir('**/run_0.50');...
dir('**/run_0.75');...
dir('**/run_1.00')]
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!