如何在UigetDir上更改UigetFolder?
13 views (last 30 days)
Show older comments
Hello
I have an old code using uigetfolder but when I run it I have error message: The function UIGETFOLDER only works on a MS-Windows PC. I wonder if I can use uigetdir to fix it or maybe there is beter way?
功能folder = uigetfolder(title, initial_path)
%UIGETFOLDER Standard Windows browse for folder dialog box.
%
% folder = uigetfolder(title, initial_path)
%
%输出:文件夹=选定文件夹(取消对话框,如果对话框)
%输入:标题=标题字符串(可选)
% initial_path = initial path (OPTIONAL, defaults to PWD)
%
%示例:文件夹= uigetfolder-默认标题和初始路径
% folder = uigetfolder('Select results folder') - default initial path
%文件夹= uigetfolder([],'C:\ Program Files') - 默认标题
%
% See also UIGETFILE, UIPUTFILE
%-----------------------------------------------------------------------------------------------
if~strcmp(computer,'PCWIN')
error_dialog_handle = errordlg(['The function ', upper(mfilename),' only works on a MS-Windows PC'],...
mfilename,...
'modal');
folder ='';
else
ifnargin < 2
initial_path = pwd;
end
ifnargin < 1 | isempty(title)
title =“选择文件夹”;
end
%错误检查
if〜ischar(标题)
错误('The title must be a string')
end
if~ischar(initial_path)
错误('The initial path must be a string')
end
if〜存在(pition_path,'dir')
错误(['The initial path: ', initial_path,' 不存在!'])
end
文件夹= uigetfolder_win32(title,initial_path);
end
%-----------------------------------------------------------------------------------------------
0 Comments
Accepted Answer
YT
on 6 Feb 2019
编辑:YT
on 6 Feb 2019
哇,我在FEX上查找了此功能,最后更新是在2000年(所以它几乎是古老的)。就像你说的那样
uigetdir(path, title)
will work just fine (which was introduced in R2006a). Just remove the error_dialogue part en change
uigetfolder_win32
to
uigetdir.
功能folder = uigetfolder(initial_path, title)
%UIGETFOLDER ^please note that I changed the position of initial_path and title; makes more sense
ifnargin < 2
initial_path = pwd;
end
ifnargin < 1 | isempty(title)
title =“选择文件夹”;
end
%错误检查
if〜ischar(标题)
错误('The title must be a string')
end
if~ischar(initial_path)
错误('The initial path must be a string')
end
if〜存在(pition_path,'dir')
错误(['The initial path: ', initial_path,' 不存在!'])
end
folder = uigetdir(initial_path, title);
end
4条评论
YT
on 8 Feb 2019
No problem. Please dont forget to click on the 'accept answer' button to close this question.
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
开始狩猎!