Changing the Number of Rows in imported Table via Edit-Field in App Designer
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
in Matlab App Designer, I'm building an App which imports a .csv.
I've added a Numeric Edit Field in which is displayed the Number of Rows of the Imported Table.
app.RowsEditField.Value = size(ImportedTable,1);
I would like to make this Edit Field interactive, so that whatever Number I type into that EditField, the Imported Table will be modified to have that number of rows.
If I change the Value to one smaller than the displayed number of Rows, can I make this 'chop' off the corresponding number of Rows in the Table?
If the Imported Table has 100 Rows, and the EditField displays '100', and I change that to 80, I'd like the App to then chop off 20 Rows, let's say the 20 first Rows, of the imported Table.
When I enter a Number greater than the number of Rows in the imported Table, it should simply reset my input to the number of rows, e.g. when I type 250 into the EditField, it should simply jump straight back at displaying 100, not add 150 rows into the Table.
Thank you most kindly in advance!
0 Commenti
Risposte (1)
Vedant Shah
il 18 Feb 2025
Modificato: Vedant Shah
il 18 Feb 2025
The following Implementation steps can be followed:
First, add two private properties to manage the imported data and the total number of rows:
properties (Access = private)
ImportedTable
TotalRows
end
Implement the“startupFcn”to load the entire table when the app is launched:
function startupFcn(app)
% Read the CSV file into a table
app.ImportedTable = readtable("yourcsvfile.xlsx");
app.UITable.Data = app.ImportedTable;
app.TotalRows = size(app.ImportedTable, 1);
% Update the Numeric Edit Field with the number of rows
app.EditField.Value = size(app.ImportedTable, 1);
end
Then, add a callback function for the Numeric Edit Field to achieve the intended functionality:
function RowsEditFieldValueChanged(app, event)
newRowCount = app.EditField.Value;
% Check if the new row count is less than the current row count
if newRowCount < app.TotalRows
app.UITable.Data = app.ImportedTable((app.TotalRows - newRowCount + 1):end, :);
elseif newRowCount > app.TotalRows
app.EditField.Value = app.TotalRows;
app.UITable.Data = app.ImportedTable;
end
This makes the app work as intended. Below is a screenshot demonstrating the app's functionality:
0 Commenti
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!