フィルターのクリア

create a input dialog with text entry and also drop down menu

51 ビュー (過去 30 日間)
franco otaola
franco otaola 2020 年 1 月 31 日
コメント済み: Rik 2020 年 1 月 31 日
hello,
i am trying to do an imput dialog where i ask the path to two files, and also have a drop down menu with three options.
something like this:
prompt_1= {'Input Path', 'Output Path'};
dlg_title_1 = 'Results files';
num_lines_1 = 1;
defaultans_1={'C:\','C:\'};
answer_1 = inputdlg(prompt_1,dlg_title_1,num_lines_1,defaultans_1);
with also a third line with a drop down menu like the following:
uidropdown(answer_1,'Items',{'Option 1','Option 2','Option 3'},'Value','Option 1');
i have found this question already answered but i couldnt understand it :/ (https://fr.mathworks.com/matlabcentral/answers/386361-combining-inputdlg-with-listdlg)
i can not get how to combine them, if someone could clarify me/help me understand would appreciate it :)

回答 (1 件)

Rik
Rik 2020 年 1 月 31 日
The easiest is probably to create a tiny GUI. More general tips can be found here, but the basic idea is something like the code below. I left adding comments and text fields to you.
function [str1,str2,opt]=inputdialog
hfig=figure('CloseRequestFcn',@close_req_fun,'menu','none');
opt_list={'Option 1','Option 2','Option 3'};
defaultans='C:\';
%set defaults
str1=defaultans;
str2=defaultans;
opt=opt_list{1};
%create GUI
set(hfig,'menu','none')
field1=uicontrol('Style', 'Edit', 'String', str1, ...
'Parent',hfig,'Units','Normalized', ...
'Position', [.1, .75, .8, .15]);
field2=uicontrol('Style', 'Edit', 'String', str2, ...
'Parent',hfig,'Units','Normalized', ...
'Position', [.1, .55, .8, .15]);
dropdown=uicontrol('Style', 'popupmenu', 'String', opt_list, ...
'Parent',hfig,'Units','Normalized', ...
'Position', [.1, .35, .8, .15]);
uicontrol('Style', 'pushbutton', 'String', 'OK', ...
'Parent',hfig,'Units','Normalized', ...
'Position', [.1 .1 .35 .2],...
'Callback','close(gcbf)');
cancel=uicontrol('Style', 'pushbutton', 'String', 'cancel', ...
'Parent',hfig,'Units','Normalized', ...
'Position', [.55 .1 .35 .2],...
'Tag','0','Callback',@cancelfun);
%wait for figure being closed (with OK button or window close)
uiwait(hfig)
%figure is now closing
if strcmp(cancel.Tag,'0')%not canceled, get actual inputs
str1=field1.String;
str2=field2.String;
opt=opt_list{dropdown.Value};
end
%actually close the figure
delete(hfig)
end
function cancelfun(h,~)
set(h,'Tag','1')
uiresume
end
function close_req_fun(~,~)
uiresume
end
  2 件のコメント
franco otaola
franco otaola 2020 年 1 月 31 日
hello,
thanks! i understand a little bit more, but the function it returns only one entry and not the three inputs that i dont get why not as it is defined in the str1/str2 and opt variables no?
Rik
Rik 2020 年 1 月 31 日
Are you calling the function like this?
[str1,str2,opt]=inputdialog

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by