Matlab對話框總結

選擇獲取文件路徑對話框

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章