필터 지우기
필터 지우기

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 CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by