Drop Down Button (App Designer) return index of repeated elements

10 次查看(过去 30 天)
I would like to select an option on the drop down button, the problem is that the options are reapeated!
Thus I would like that the drop down button return the option + the index of the option(S) that correspond to the chosen option.
For instance:
if the Appliance_Manufacturer ={'x','x','x','x','x','y,'z'} (Cell Array)
I would like to make the items list look like this:
than If I choosed the x, I wanna get:
Select_Manufacturer = [1,2,3,4,5]
which are the indexes where x is.
This is my primitive code:
function ApplianceManufacturerDropDownValueChanged(app, event)
A = app.Appliance_Manufacturer{:};
B = cellfun(@(v)sort(char(v)),A,'uni',0);
C = cellfun(@double,unique(B),'uni',0);
app.ApplianceManufacturerDropDown.Items = {app.Appliance_Manufacturer{:}};
app.ApplianceManufacturerDropDown.ItemsData = 1:length(app.ApplianceManufacturerDropDown.Items);
Select_Manufacturer = app.ApplianceManufacturerDropDown.Value;
I have tried to play with the unique function but I didn't get any good results.
I would appreciate any help, and thanks in advance!


Jon 2022-1-12
Here's a skeleton of the logic regarding using unique. You will have to adapt details regarding getting the users selection etc. Here I just illustrate for when the user selects x as you describe in your question
Appliance_Manufacturer ={'x','x','x','x','x','y','z'}
[item_list,~,ic] = unique(Appliance_Manufacturer)
idx = strmatch('x',item_list)
Select_Manufacturer = find(ic==idx)

更多回答(0 个)


Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息




Community Treasure Hunt

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

Start Hunting!

Translated by