Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How do I find output as the path of any input stored in cells?
1 回表示 (過去 30 日間)
古いコメントを表示
Suppose I have the main folder 'X' which has a subfolder 'a'. now a is like a linear array with n elements. Now picking any random element out of it, the output should show the path i.e, X\a\n. Like 'a' there would be columnar till z. So it would be like a rectangular matrix. Need urgent help with this
回答 (1 件)
Walter Roberson
2017 年 12 月 4 日
projectdir = fullfile('X', 'a');
dinfo = dir( projectdir );
dinfo(ismember({dinfo.name}, {'.', '..'})) = []; %remove . and ..
numentries = length(dinfo);
random_entry_idx = randi(numentries);
random_entry_filename = dinfo(random_entry_idx).name;
random_name = fullfile(projectdir, random_entry_filename);
3 件のコメント
Walter Roberson
2017 年 12 月 5 日
編集済み: Walter Roberson
2017 年 12 月 5 日
projectdir = fullfile('X', 'a');
if ~exist(projectdir, 'dir')
error('Folder "%s" does not exist relative to here', projectdir);
end
dinfo = dir( projectdir );
dinfo(ismember({dinfo.name}, {'.', '..'})) = []; %remove . and ..
numentries = length(dinfo);
if numentries == 0
error('Folder "%s" exists but has no files in it', projectdir);
end
random_entry_idx = randi(numentries);
random_entry_filename = dinfo(random_entry_idx).name;
random_name = fullfile(projectdir, random_entry_filename);
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!