Help filtering a table from a dropdown in App designer.
Show older comments
Hi there. I have a rather large table (nearly 80 columns) that I would like to be able use in app designer to have drop downs used to plot different variables.
I have 10 widgets with serial numbers that have about 75 data observations. I would like to have a drop down filter the data table from the large table to a smaller section of just the selected widget's serial number, and then plot variables selected as a simple xy scatter plot. But I cannot seem to get these drop down selections to work with the table.
Only thing I can think of, is the data table is so large, I used unique(table(table.serialnumber,:) to find just the unique serial numbers. So maybe it's looking into that 10x1 array instead of the table based on the serial number? Any reference to the actual data to filter is to the entire table though.
Answers (1)
Attached is an m-file you can run that creates a table of data and a popupmenu to change what's shown in the table.
Try to adapt it to your app. Be aware that a popupmenu uicontrol (as I use here) and a uidropdown (as you'd use in your app) behave similarly, but their properties are not the same (e.g., the 'Value' of a uidropdown is an element of 'Items' or 'ItemsData', but the 'Value' of a popupmenu uicontrol is an index into the 'String', 'String' being analogous to uidropdown 'Items').
However, the logic is the same as what (I think) you are trying to do.
table_filter_demo
2 Comments
Adam
on 10 Jan 2023
Try the code as follows. Close your app and restart it to test it because the way you had it before would've replaced your uitable (app.UITable2) with a table variable (tfilter).
%create vector of turbine serial numbers for dropdown pulling the unique values from the column in the spreadsheet.
TurbineSerials=unique(app.AllData.turbine_serial)
%load into dropdown selections
app.TurbineDropDown.Items=TurbineSerials
% .Value is the one to use, so this is ok:
SelectedTurbine = app.TurbineDropDown.Value;
% I think this should be ok:
tfilter=app.AllData(app.AllData.turbine_serial==SelectedTurbine,:)
% this replaces app.UITable2 with tfilter ... :
% app.UITable2=tfilter
% ... instead you want to set the Data of app.UITable2:
app.UITable2.Data = tfilter;
app.UITable2.ColumnName=tfilter.Properties.VariableNames;
If you continue to get errors, then upload the .mlapp file here (using the paperclip icon) and I can take a look.
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!