選擇獲取文件路徑對話框
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