Assigning Values in a Popup menu String

1 view (last 30 days)
jeo47
jeo47 on 26 May 2015
Answered: Image Analyst on 26 May 2015
Hi, I am currently writing a simple code in which I want to choose a number from a drop-down string in two separate pop-up menus and then apply a function to these values where the answer is displayed in a textbox. For example, the user selects the number 4 from one drop-down and the number 9 from another. The user clicks the 'add' pushbutton and the number 13 is displayed in the answer textbox.
My issue is with converting the string values to text. I am currently using the code below:
popupmenu1 = get(handles.popupmenu1, 'Value');
input1 = str2num(get(handles.popupmenu1,'String'));

Answers (1)

Image Analyst
Image Analyst on 26 May 2015
Try something like this:
selectedItem1 = get(handles.popupmenu1, 'Value');
list1 = get(handles.popupmenu1, 'String');
input1 = str2double(list1{selectedItem1});
selectedItem2 = get(handles.popupmenu2, 'Value');
list2= get(handles.popupmenu2, 'String');
input2 = str2double(list2{selectedItem2});
results = input1 + input2;

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!