Filter Data In Table App Designer

16 Ansichten (letzte 30 Tage)
Eshe Boyette
Eshe Boyette am 29 Apr. 2020
Beantwortet: Deepak am 8 Nov. 2024 um 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

Antworten (1)

Deepak
Deepak am 8 Nov. 2024 um 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.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by