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 件のコメント

Rik
Rik 2020 年 3 月 31 日
As everything: try to slice up your problem into smaller problems you can solve. Into what parts could you cut this problem? Which of those is causing you issues to solve?
Dinouk Goonewardena
Dinouk Goonewardena 2020 年 3 月 31 日
firstly I already got the popumenu1 to store all my Y numbers, so now I need it to be able to depending on the Y number populate my popupmenu2 (2nd popupmenu) with the versions
Rik
Rik 2020 年 3 月 31 日
It looks like the ismember function would solve most of this problem.
Dinouk Goonewardena
Dinouk Goonewardena 2020 年 3 月 31 日
do you have a sample code for my case?
Rik
Rik 2020 年 3 月 31 日
Can you share sample data? That would make sure you can use my code directly and it would remove the need for me to create data from scratch or copy it from your screenshot.
Dinouk Goonewardena
Dinouk Goonewardena 2020 年 3 月 31 日
I'm using this data from an API which has a key and password aswell, which I cant share. If you can just make some radom data sets, I should be able to understand it
Rik
Rik 2020 年 3 月 31 日
Feel free to create some random data that has approximately the same characteristics as your real data. I don't need your actual data, just something similar to what you already shared in your screenshot.
Dinouk Goonewardena
Dinouk Goonewardena 2020 年 3 月 31 日
編集済み: Dinouk Goonewardena 2020 年 3 月 31 日
Ynumber=[1;1;2;3;5];
Version={'AP'; 'AP_R' ;'AP' ;'TI1' ;'TI2'};
mytable= table(Ynumber,Version);
Rik
Rik 2020 年 3 月 31 日
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 2020 年 3 月 31 日
編集済み: Dinouk Goonewardena 2020 年 3 月 31 日
A better example of data i guess, So the first 2 Y number (1) has 2 versions, which should be in the popupmenu2

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2020 年 3 月 31 日

0 投票

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 件のコメント

Dinouk Goonewardena
Dinouk Goonewardena 2020 年 4 月 1 日
b = extractfield(data_sheet2,'Version');
popupMenuItems = get(handles.popupmenu1, 'String');
Y_selected = char(popupMenuItems{get(handles.popupmenu1,'Value')}); -----------(Error: Expected one output from a curly brace or dot indexing expression, but there were 12475 results.)
selected_Ynumber=data_sheet2.YNumber(Y_selected);
L=ismember(data_sheet2.YNumber,selected_Ynumber);
handles.popupmenu2.String=b(L);
I get an error for Y_selected, any idea of a fix for it?
Rik
Rik 2020 年 4 月 1 日
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 2020 年 4 月 1 日
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 2020 年 4 月 1 日
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeVariables についてさらに検索

製品

リリース

R2016b

タグ

質問済み:

2020 年 3 月 31 日

コメント済み:

Rik
2020 年 4 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by