How to call popup menu data in push button?

1 view (last 30 days)
adi kul
adi kul on 31 May 2016
Answered: Geoff Hayes on 2 Jun 2016
Hello, With the help of popup menu I am getting data from the user as follows:
selection = get(hObject, 'Value');
switch selection
case 1
h=msgbox('Please select the Surface');
case 2
surface2=0;
case 3
surface2=1;
prompt = {'Enter the radius (mm)','Enter the x ','Enter the y '};
dlg_title = 'Sphere';
num_lines = 1;
defaultans = {'','0','0'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
r_sphere=str2num(answer{1});
x0=str2num(answer{2});
y0=str2num(answer{3});
From above I get some specific inputs from users. Now I need to use them in later part of the code. I have a push button where I calculate things and there remains my remaining code. Now what is my problem is I am not able to call back the popup menu inputs to run the code in pushbutton. Can anyone suggest a way to get values of popup into push button?
  1 Comment
TastyPastry
TastyPastry on 31 May 2016
Can you take a screenshot to show what your GUI looks like

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 2 Jun 2016
adi - I am assuming that you are using GUIDE to create your GUI (given the hObject reference in the above code). If that is the case, then you can use the handles structure to reference the popupmenu control from within the pushbutton callback. For example,
function pushbutton1_Callback(hObject, eventdata, handles)
selectedItemIndex = get(handles.popupmenu1,'Value');
% etc.
The above will allow you to access the index of the selected item of the popup menu from within the pushbutton callback.

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!