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

12 Ansichten (letzte 30 Tage)
Maruti B Patil
Maruti B Patil am 17 Jul. 2016
Kommentiert: Walter Roberson am 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.

Antworten (2)

Image Analyst
Image Analyst am 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 am 17 Jul. 2016
Bearbeitet: Walter Roberson am 17 Jul. 2016
Thanks but, it is giving the following error;
Reference to non-existent field 'Value'.
  4 Kommentare
Image Analyst
Image Analyst am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by