App Developer: delete table rows

26 views (last 30 days)
There are lots of questions and answers for how to delete table rows in Matlab, but none of the solutions work very well in Matlab App Developer. In my app I have a table that is populated with data entered with pushbuttons and edit field boxes. When data is entered into the table, the table grows in size by 1 row. All of that works just fine.
I want a pushbutton that will reset the table to its default size of no rows. To achieve this I created a pushbutton called "Clear" and the following code:
% Button pushed function: ClearButton
function ClearButtonPushed(app, event)
app.UITable.Data =[];
end
Undesirablly, this code will replace all the data in the table with zeros. After entering new data into the table, instead of appearing on the first row, the new data will appear after all the zero rows. I have attached pictures for clarificaiton. The image on the left is before hitting the clear button. The image on the right is after hitting the clear button and then entering new data for one row. I would like for the image on the right to have only one row with the new data and no zero rows.
Similarly, I would like to click on one row and then press a "delete" pushbutton to delete only that specific row. For example looking at the image on the right, the 1st column numbers are 1, 2, 3, 1. If I click on the row with the 3 then I want the sequence for the frist column to appear as 1, 2, 1 with no zero row between the 2 and the second 1.

Accepted Answer

William Gaillard
William Gaillard on 6 Mar 2019
Ah, of course I solve my problem shortly after posting the question. Because I have multiple ways to enter data into the table I need a variable that keeps up with the current row so that I don't overwrite data. I just added a line after app.UITable.Data =[];
that resets the row number to 1.
  1 Comment
Jorge Torres
Jorge Torres on 19 Apr 2020
Can I see your code, please?.
Currently I would like to delete a selected row from a table using a "delete button", but I don`t now how exactly.
Thanks.

Sign in to comment.

More Answers (2)

William Gaillard
William Gaillard on 6 Mar 2019
Forgot to attach the image. Here it is

William Gaillard
William Gaillard on 6 Mar 2019
cleartable.jpg
I guess it is easier if I attach it this way :)

Categories

Find more on Tables 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!