设置编译后的matlab GUI文件夹
Set compiled matlab GUI folder
我有一个 Matlab GUI(我编译它),为了加载一个文件,我按下了一个使用这一行的按钮
[file, folder] = uigetfile({'*.jpg;*.gif;*.bmp','All Image Files'},' Select image');
如果我再次按下按钮,它会打开安装软件的文件夹。我怎样才能改变它,让它记住并打开我使用的最后一个文件夹?
谢谢。
uigetfile
的 folder
输出是选择的路径。将其用作下一次调用 uigetfile
的输入
[file, folder] = uigetfile({'*.jpg;*.gif;*.bmp','All Image Files';},...
'Select Image', folder);
这是来自 doc uiputfile
的示例,但它也适用于 uigetfile
。
根据 uigetfile
的文档,您可以指定可选的第三个输入参数,DefaultName
:
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec,DialogTitle,DefaultName)
displays a dialog box
in which the file name specified by DefaultName
appears in the File
name field. DefaultName
can also be a path or a path/filename. In
this case, uigetfile
opens the dialog box in the folder specified by
the path. You can use .
,..
,\
, or /
in the DefaultName
argument. To specify a folder name, make the last character of
DefaultName
either \
or /
. If the specified path does not exist,
uigetfile
opens the dialog box in the current folder.
您可以将上次打开的文件夹存储到您的 GUI 中,并在触发按钮回调时访问它。
例如:
function testgui
h.f = figure('MenuBar', 'none', 'NumberTitle', 'off', 'ToolBar', 'none');
h.b = uicontrol('Parent', h.f, 'Style', 'pushbutton', 'Units', 'Normalized', ...
'Position', [0.1 0.3 0.8 0.4], 'String', 'Pick a file');
h.l = uicontrol('Parent', h.f, 'Style', 'text', 'Units', 'Normalized', ...
'Position', [0.1 0.1 0.8 0.1], 'String', '');
setappdata(h.f, 'lastfolder', '');
h.l.String = sprintf('Last Directory: %s', '');
h.b.Callback = @(o, e) abutton(h);
end
function abutton(h)
lastfolder = getappdata(h.f, 'lastfolder');
[file, folder] = uigetfile({'*.jpg;*.gif;*.bmp','All Image Files'},' Select image', lastfolder);
if folder ~= 0
setappdata(h.f, 'lastfolder', folder);
h.l.String = sprintf('Last Directory: %s', folder);
end
end
请注意,当 GUI 关闭并重新打开时,此方法会重置为您的当前目录。
我有一个 Matlab GUI(我编译它),为了加载一个文件,我按下了一个使用这一行的按钮
[file, folder] = uigetfile({'*.jpg;*.gif;*.bmp','All Image Files'},' Select image');
如果我再次按下按钮,它会打开安装软件的文件夹。我怎样才能改变它,让它记住并打开我使用的最后一个文件夹?
谢谢。
uigetfile
的 folder
输出是选择的路径。将其用作下一次调用 uigetfile
[file, folder] = uigetfile({'*.jpg;*.gif;*.bmp','All Image Files';},...
'Select Image', folder);
这是来自 doc uiputfile
的示例,但它也适用于 uigetfile
。
根据 uigetfile
的文档,您可以指定可选的第三个输入参数,DefaultName
:
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec,DialogTitle,DefaultName)
displays a dialog box in which the file name specified byDefaultName
appears in the File name field.DefaultName
can also be a path or a path/filename. In this case,uigetfile
opens the dialog box in the folder specified by the path. You can use.
,..
,\
, or/
in theDefaultName
argument. To specify a folder name, make the last character ofDefaultName
either\
or/
. If the specified path does not exist,uigetfile
opens the dialog box in the current folder.
您可以将上次打开的文件夹存储到您的 GUI 中,并在触发按钮回调时访问它。
例如:
function testgui
h.f = figure('MenuBar', 'none', 'NumberTitle', 'off', 'ToolBar', 'none');
h.b = uicontrol('Parent', h.f, 'Style', 'pushbutton', 'Units', 'Normalized', ...
'Position', [0.1 0.3 0.8 0.4], 'String', 'Pick a file');
h.l = uicontrol('Parent', h.f, 'Style', 'text', 'Units', 'Normalized', ...
'Position', [0.1 0.1 0.8 0.1], 'String', '');
setappdata(h.f, 'lastfolder', '');
h.l.String = sprintf('Last Directory: %s', '');
h.b.Callback = @(o, e) abutton(h);
end
function abutton(h)
lastfolder = getappdata(h.f, 'lastfolder');
[file, folder] = uigetfile({'*.jpg;*.gif;*.bmp','All Image Files'},' Select image', lastfolder);
if folder ~= 0
setappdata(h.f, 'lastfolder', folder);
h.l.String = sprintf('Last Directory: %s', folder);
end
end
请注意,当 GUI 关闭并重新打开时,此方法会重置为您的当前目录。