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

조회 수: 10 (최근 30일)
Maruti B Patil
Maruti B Patil 2016년 7월 17일
댓글: Walter Roberson 2016년 7월 17일
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.

답변 (2개)

Image Analyst
Image Analyst 2016년 7월 17일
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 2016년 7월 17일
편집: Walter Roberson 2016년 7월 17일
Thanks but, it is giving the following error;
Reference to non-existent field 'Value'.
  댓글 수: 4
Image Analyst
Image Analyst 2016년 7월 17일
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 2016년 7월 17일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by