Help filtering a table from a dropdown in App designer.

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.

답변 (1개)

Voss
Voss 2023년 1월 9일
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

So, your function is exactly what I'm going for. But I still can't seem to get it to work.
here's the parts of my code that are relevant.
%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
SelectedTurbine = app.TurbineDropDown.Value; (I've tried .value, .Items, .ItemData still the same)
tfilter=app.AllData(app.AllData(:,turbine_serial)==SelectedTurbine,:) (if i try app.AllData.turbine_serial i get the same error as described at the bottom of this post, but it returns the actual serial number.
app.UITable2=tfilter
app.UITable2.ColumnName=tfilter.Properties.VariableNames;
I'm using the table as a way to test the functionality. If the table gets populated, I know I have a properly filtered dataset I can use for the plotting functionality.
Error I'm getting is: Unrecognized function or variable 'turbine_serial'.
even though I know it's in my original table at least. I must be cutting something out somewhere and not realizing I'm making something into a vector instead of making it a cut down table?
Voss
Voss 2023년 1월 10일
이동: Voss 2023년 1월 10일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 1월 9일

이동:

2023년 1월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by