Filter Data In Table App Designer

16 次查看(过去 30 天)
Eshe Boyette
Eshe Boyette 2020-4-29
回答: Deepak 2024-11-8,10:27
I am trying to create a all back so that when I add a value to an edit field and push a button, only certain data displays from my data table. It is not filtering. Please help. I am new to MATLAB. Thank you!
t = readtable('us-states.xlsx');
app.UITable.Data = t;
Filter = app.FIPSIDEditField.Value;
numRows = size (app.t,1);
k=1;
for i = 1:numRows
if app.UITable.Data{i,4} == Filter
RowstoDel(1,k) = i;
k = k + 1;
end
end

回答(1 个)

Deepak
Deepak 2024-11-8,10:27
To filter the data table based on the user input in MATLAB, first we need to ensure that the Excel file is correctly loaded into the application, and the table data is properly assigned to theUITable”. Next, we can retrieve filter value from the edit field, converting it to the appropriate data type if necessary (e.g., using “str2double” for numeric comparisons). Next, we can use logical indexing to identify and extract the rows in the data table that match the specified FIPS ID.
Finally, we can update the “UITable with this filtered subset of data, ensuring that the column index used in the filtering corresponds to the correct column containing the FIPS ID in the dataset.
Here is the sample MATLAB code to accomplish the same:
function FilterButtonPushed(app, event)
t = readtable('us-states.xlsx');
% Get the filter value from the edit field
Filter = app.FIPSIDEditField.Value;
% Convert the filter value to a number if necessary
if ischar(Filter)
Filter = str2double(Filter);
end
% Find the rows that match the filter
% Assuming the FIPS ID is in the 4th column
matchRows = t{:, 4} == Filter;
% Filter the table to only include matching rows
filteredTable = t(matchRows, :);
% Update the UITable with the filtered data
app.UITable.Data = filteredTable;
end
Please find attached the documentation of functions used for reference:
I hope this assists in resolving the issue.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by