Matlab彈出窗口
1.文件打開操作
uigetfile命令
打開以.m結尾的文件
[FileName,PathName] = uigetfile('*.m','Select the MATLAB code file');
打開不同格式的文件
[filename, pathname] = uigetfile( ...
{'*.m;*.fig;*.mat;*.slx;*.mdl',...
'MATLAB Files (*.m,*.fig,*.mat,*.slx,*.mdl)';
'*.m', 'Code files (*.m)'; ...
'*.fig','Figures (*.fig)'; ...
'*.mat','MAT-files (*.mat)'; ...
'*.mdl;*.slx','Models (*.slx, *.mdl)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a file');
打開指定路徑的文件
uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
'*.*','All Files' },'mytitle',...
'C:\myfiles\my_examples\gbtools\setpos1.png')
2.路徑選擇對話框
uigetdir函數
打開C盤
dname = uigetdir('C:\');
注:cd命令,可以進入具體路徑。
3.文件保存操作
uiputfile函數
以指定文件名的后綴保存
file,path] = uiputfile('*.mat','Save Workspace As');
4.運行進度條
waitbar函數
使用格式如下:(x為0~1之間)
h = waitbar(x,'message')
關閉、刪除對話框
close(h);
delete(h);
為對話框提供取消按鈕
waitbar(x,'message','CreateCancelBtn','button_callback')
waitbar(0.5,'message','CreateCancelBtn',delete_h(h') % 取消函數為 function delete_h(h) delete
5.錯誤對話框
errordlg('File not found','File Error');
6.警告對話框
warndlg
多行顯示
warndlg({'程序' '警告'});
7.用戶提示對話框
msgbox
h = msgbox('Operation Completed');
顯示圖標
h = msgbox(Message,Title,Icon)
8.提問對話框
questdlg
例子
choice = questdlg('Would you like a dessert?', ...
'Dessert Menu', ...
'Ice cream','Cake','No thank you','No thank you');
% Handle response
switch choice
case 'Ice cream'
disp([choice ' coming right up.'])
dessert = 1;
case 'Cake'
disp([choice ' coming right up.'])
dessert = 2;
case 'No thank you'
disp('I''ll bring you your check.')
dessert = 0;
end
9.輸入對話框
inputdlg
prompt = {'Enter matrix size:','Enter colormap name:'};
dlg_title = 'Input';
num_lines = 1;
def = {'20','hsv'};
answer = inputdlg(prompt,dlg_title,num_lines,def);