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

11 vues (au cours des 30 derniers jours)
Hidd_1
Hidd_1 le 12 Jan 2022
Réponse apportée : Jon le 12 Jan 2022
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!

Réponse acceptée

Jon
Jon le 12 Jan 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)

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by