MATLAB Answers

How to create input dialog box with drop down menu...????

36 views (last 30 days)
Maruti B Patil
Maruti B Patil on 17 Jul 2016
Commented: Walter Roberson on 17 Jul 2016
I have the following table
Input A B
X32 27 4
X46 39 5
X60 59 7
X74 87 9
X88 131 12
X102 194 16
For this table, I want to create input dialog box with a drop-down menu.
Suppose I select X60 from the drop-down menu as an input value, then it should give the output values of A and B as 59 and 7 respectively.

Answers (2)

Image Analyst
Image Analyst on 17 Jul 2016
First you have to put column 1 of the table into the popup. I'm assuming you know how to do that. If not, I think it's something like this:
C = table2cell(T) % Convert table to cell array
handles.popup1.String = C{:, 1};
Though perhaps you don't need to convert to a cell array first now.
Then you need to get the index they selected from the popup and use that to get the other two numbers from the table. Something like (untested)
selectedIndex = handles.popup1.Value; % A number
A = T{selectedIndex, 2};
B = T{selectedIndex, 3};
You can do that from any callback you want since all callbacks have access to all uicontrols.

Maruti B Patil
Maruti B Patil on 17 Jul 2016
Edited: Walter Roberson on 17 Jul 2016
Thanks but, it is giving the following error;
Reference to non-existent field 'Value'.
  4 Comments
Walter Roberson
Walter Roberson on 17 Jul 2016
I speculate that somewhere in your code, you overwrote handles.popup1 with something else. For example it is not uncommon for people to try something like
handles.popup1 = get(handles.popup1, 'Value');
under the thought that they are recording a copy of the value under the name popup1 and that MATLAB will know that when handles.popup1 is used in the context that requires a handle that MATLAB will know to refer to the handle instead of to the copy of the value that was saved under the same name.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!