How to get selected folders from multiple folders in a directory?

조회 수: 10 (최근 30일)
sam moor
sam moor 2018년 10월 20일
댓글: Stephen23 2018년 10월 25일
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
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?
sam moor
sam moor 2018년 10월 24일
I want to select randomly four of the folders name from the list of the folders. For example I have a main folder "run". In "run" folder I have run_0.01, run_0.05, run_0.10, run_0.25, 0.3,0.5,0.6,0.75,1.0. I want to select randomly four names run_0.05, run_0.25, run_0.5, run_0.75.
If we can't randomly select the folders than I can also go with user selects folders.
Any advice is appreciated

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

채택된 답변

Stephen23
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
sam moor
sam moor 2018년 10월 24일
Thank you Stephen.
If we want to select specific 6 folders such as run1, run2, run3...run6 Do we need to change N?
Stephen23
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
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
Image Analyst 2018년 10월 22일
Try (untested)
files = [dir('**/run_0.25');...
dir('**/run_0.50');...
dir('**/run_0.75');...
dir('**/run_1.00')]
sam moor
sam moor 2018년 10월 24일
it listed all the files in the folders....but not folders

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by