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

6 visualizzazioni (ultimi 30 giorni)
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:
{'x','y','z'}
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;
end
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!

Risposta accettata

Jon
Jon il 12 Gen 2022
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)

Più risposte (0)

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by