选择获取文件路径对话框
selpath = uigetdir(path,'我是标题')
注:path可以指定默认打开的文件路径,path若为空,则打开当前文件路径
输入信息参数对话框
prompt = {'Enter matrix size:','Enter colormap name:'};
title = 'Input';
dims = [1 35];
definput = {'20','hsv'};
answer = inputdlg(prompt,title,dims,definput)
注:这里返回的参数是cell格式,如果想调用数值的话,需要转换一下
user_val = str2num(answer{1})
按钮选择问题对话框
answer = questdlg('Would you like a dessert?', ...
'Dessert Menu', ...
'Ice cream','Cake','No thank you','No thank you');
% 最后的'No thank you'为默认选择
注:当然可以根据用户选择做出不同的响应
% Handle response
switch answer
case 'Ice cream'
disp([answer ' coming right up.'])
dessert = 1;
case 'Cake'
disp([answer ' coming right up.'])
dessert = 2;
case 'No thank you'
disp('I''ll bring you your check.')
dessert = 0;
end
输出消息对话框
f = msgbox('Operation Completed','Success');
f = msgbox('Invalid Value', 'Error','error');
注:还可以在对话框中添加其他小图标或者自定义图片
警告信息对话框
f = warndlg('Pressing ACCEPT clears memory','Warning');
列表选择对话框
list = {'Red','Yellow','Blue',...
'Green','Orange','Purple'};
[indx,tf] = listdlg('ListString',list);
注:indx为用户选择的选项在数组中的索引
tf是一个逻辑值,如果用户点取消则为0,否则是1