MATLAB Answers

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

75 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.

  0 Comments

Sign in to comment.

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.

  0 Comments

Sign in to comment.


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

Show 1 older comment
Maruti B Patil
Maruti B Patil on 17 Jul 2016
I am using MATLAB 2016a.
By using set() & get() also I am getting following error.
Error using get
Conversion to double from struct is not possible.
Image Analyst
Image Analyst on 17 Jul 2016
You forgot to include the error message. Please include ALL of it, not just a part of it. Namely, I can't see your line of code that throws the error and I know that the line of code is included in the full error message. You must include ALL the red text if we are to debug it.
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.