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

11 Ansichten (letzte 30 Tage)
Hidd_1
Hidd_1 am 12 Jan. 2022
Beantwortet: Jon am 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!

Akzeptierte Antwort

Jon
Jon am 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)

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by