、オプションの3番目の入力引数、DefaultName
指定することができます:あなたはあなたのGUIに最後に開いたフォルダを保存し、ボタンのコールバックが起動されたときにそれをアクセスすることができます
[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
注意。
それは素晴らしい作品と非常にうまく動作します。 OpeningFcnに関数testguiのコンテンツを追加するにはどうしたらいいですか? – user2916044
'OpeningFcn'に' setappdata'だけ必要です。 – excaza
私はこのエラーがあります:未定義の変数 "h"またはクラス "h.f"。 V1baのエラー> V1ba_OpeningFcn(75行目) setappdata(h.f、 'lastfolder'、 ''); gui_mainfcn(行220)のエラー feval(gui_State.gui_OpeningFcn、gui_hFigure、[]、guidata(gui_hFigure)、varargin {:}); V1baのエラー(行42) gui_mainfcn(gui_State、varargin {:});私はどのシェルを修正するのですか? – user2916044