UITable callback from another table not updating for GUI

6 views (last 30 days)
Fallow John
Fallow John on 2 Apr 2022
Answered: Kevin Holly on 4 Apr 2022
Using the App Designer I'm trying to take two columns from Table A, combine them so [2 3] becomes '2-3' on the first column of Table B and then add an additional manual entry value on the second column.
But before I figure out how to get data from specific columns of the table I can't get any data to be pushed across from Table A to Table B at all.
I've followed some other comments trying to set up a callback from one table to update another table.
Where the table data seems to be correct as the user is editing Table A.
Currently the callback for the 'Update Data' button tries to set the data for the second table but nothing happens.
Ideally I would like Table B to update as the values are edited in table A but I'm happy with a button to make that happen.

Answers (1)

Kevin Holly
Kevin Holly on 4 Apr 2022
Please see the app attached.
Here are the callbacks I used in the app. Note, event.NewData is only the value you change and not the whole table. The values of the whole table for table 1 and 2 are app.UITable.Data and app.UITable2.Data, respectively.
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.UITable.Data = round(10*rand(12,2));
app.UITable2.Data = zeros(12,2);
app.UITable2.Data(:,1) = app.UITable.Data(:,1)-app.UITable.Data(:,2);
app.UITable2.Data(:,2) = app.UITable.Data(:,1)+app.UITable.Data(:,2);
end
% Cell edit callback: UITable
function UITableCellEdit(app, event)
indices = event.Indices;
newData = event.NewData;
app.UITable2.Data(:,1) = app.UITable.Data(:,1)-app.UITable.Data(:,2);
app.UITable2.Data(:,2) = app.UITable.Data(:,1)+app.UITable.Data(:,2);
end
end
When a value in table 1 is changed, the app runs the UITableCellEdit function. The line below replaces column 1 in table 2 with values equal to the first column in table 1 subtracted by the second column in table 1.
app.UITable2.Data(:,1) = app.UITable.Data(:,1)-app.UITable.Data(:,2);
The line below replaces column 1 in table 2 with values equal to the first column in table 1 plus the second column in table 1.
app.UITable2.Data(:,2) = app.UITable.Data(:,1)+app.UITable.Data(:,2);

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by