Add new row to UITable

28 次查看(过去 30 天)
Marcel
Marcel 2022-11-15
编辑: Ishu 2024-8-29
Hi i've done some research and was curious if there was a more "effecient" way on how to add new rows with data to a UITable in R2021a using the App-Designer. I got it to work but to me it feels like it would take a lot of afford to keep reading all the existing data and then add the new one to it.
%hTable: handle to the table
%newRow : the row of data you want to add to the table.
oldData = get(hTable,'Data');
newData = [oldData; newRow];
set(hTable,'Data',newData)
This for sure works just fine but im going to display quite a lot of data in there overtime. Right now i can display about 150 rows, which is kinda fine when thinking about it being used as a log, but is still important to view.
I approach to this right now is to append the lines to a file and then clear the UITable from time to time so it wont start lagging. Like i said its all working fine for me but im curious if there is something better to this

回答(1 个)

Ishu
Ishu 2024-8-29
编辑:Ishu 2024-8-29
Hi Marcel,
I understand that you are looking for a method to add rows to a "UITable" in App Designer.
You can achieve this by using the "startupFcn" callback.
To add the "startupFcn" callback, follow these steps:
  1. Go to "Code View" in App Designer.
  2. In the "Editor" tab, click on the "+" sign in "Callbacks" column.
  3. From the dropdown in "Callback" select " StartupFcn" from the list. This will add a "startupFcn" callback to your code.
In the "startupFcn", add the following line of code:
% create your matrxi data and add in the UITable using below code.
app.UITable.Data = [matrix data];
This code initializes the "UITable" with "matrix data" when the app starts.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by