Automatically take folder directories of one level up
114 次查看(过去 30 天)
显示 更早的评论
I have 3 folders of images. Now I want to enter into one folder and select that directory. Then I want matlab to go back to one level up and automatically select other two folder's directory. Is there any easirer way to do that?
Thanks in advance
0 个评论
采纳的回答
Image Analyst
2020-11-13
Try this:
[parentFolder, thisFolder] = fileparts(ImageFolder)
fileListing = dir(parentFolder) % List of everything: folders and files:
% Get a list of only the folders
areAFolder = [fileListing.isdir];
% Extract only those items that are folders, not files;
folderListing = fileListing(areAFolder)
% Just for fun, list all the folders that we found:
fprintf('Found these %d child folders of "%s" :\n', length(folderListing), parentFolder)
for k = 1 : length(folderListing)
thisFolder = fullfile(folderListing(k).folder, folderListing(k).name);
fprintf('%s\n', thisFolder);
end
Do not use addpath() ! !
更多回答(1 个)
Jon
2020-11-13
编辑:Jon
2020-11-13
You can specify the full path to the directories you want to open rather than changing the directory that MATLAB is running in. So keep MATLAB in the same directory and only change the path e.g. 'myDir1/mysubDir2/myfileA.ext' back of 'myDir1/myfileB.ext' to the file you want to open
3 个评论
Jon
2020-11-13
That's fine, just specify the full path to where the data is for example
X = readmatrix('C:\TEMP\matlab\data01.csv')
or am I somehow not understanding your question?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!