MATLAB Answers

2 popup menus connected

조회 수: 2(최근 30일)
Dinouk Goonewardena
Dinouk Goonewardena 31 Mar 2020
댓글: Rik 1 Apr 2020
I'm trying to create 2 popup menus the first one stores all the 'Y numbers' and then depending on that I want to get the corressponding 'Version'. Note some Y numbers have more than 1 version. Hence I need help to figure it out

  댓글 수: 10

표시 이전 댓글 수: 7
Dinouk Goonewardena
Dinouk Goonewardena 31 Mar 2020
Ynumber=[1;1;2;3;5];
Version={'AP'; 'AP_R' ;'AP' ;'TI1' ;'TI2'};
mytable= table(Ynumber,Version);
Rik
Rik 31 Mar 2020
Your code will generate a variable of the dataset class (which will apparently be removed in a future release), while your screenshot is of the table datatype. The data also doesn't look remotely similar to me. Should the first dropdown contain 0.1, 0.3, and 0.2, with the second dropdown containing only a single option after the first selection has been made?
Dinouk Goonewardena
Dinouk Goonewardena 31 Mar 2020
A better example of data i guess, So the first 2 Y number (1) has 2 versions, which should be in the popupmenu2

로그인 to comment.

답변(1개)

Rik
Rik 31 Mar 2020
Ynumber=[1;1;2;3;5];
Version={'AP'; 'AP_R' ;'AP' ;'TI1' ;'TI2'};
mytable= table(Ynumber,Version);
%Y_selected=get(handles.dropdown_Y,'Value');
Y_selected=2;
selected_Ynumber=mytable.Ynumber(Y_selected);
L=ismember(mytable.Ynumber,selected_Ynumber);
versions=mytable.Version(L);
The last variable can be used as the String property of your second dropdown.

  댓글 수: 4

표시 이전 댓글 수: 1
Rik
Rik 1 Apr 2020
Yes, use the code I suggested. If your Ynumber column contains the items in your first dropdown, then the code I showed will work.
A more general rule of thumb: you are combining several steps in one line. Look at each step separately and try to determine if you expected those data types and sizes.
val=get(handles.popupmenu1,'Value');
item=popupMenuItems{val};
Y_selected = char(item);
Which of these lines is nog returning an error? Where is the data type different from what you expect?
Dinouk Goonewardena
Dinouk Goonewardena 1 Apr 2020
sorry not that line but this;
selected_Ynumber=data_sheet2.YNumber(Y_selected); -----------(Error: Expected one output from a curly brace or dot indexing expression, but there were 12475 results.)
L=ismember(data_sheet2.YNumber,selected_Ynumber);
handles.popupmenu2.String=b(L);
Rik
Rik 1 Apr 2020
The code I posted works. You can't send me the data you're working with, so you will have to provide example data that will reproduce the error. It seems like Y_selected might not be a scalar, or data_sheet2 is not a table or scalar struct.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그

제품


릴리스

R2016b

Translated by