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);