create a input dialog with text entry and also drop down menu
55 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 :)
0 Kommentare
Antworten (1)
Rik
am 31 Jan. 2020
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
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!