Complete executing celledit before any other function is trigerred

3 views (last 30 days)
I am trying to create a table (UITable_2 with C,D) based on the selected cell of another table (UITable with A,B) . Also, I am trying to set the data of UITable_2 to be editable.
However, while editing a field of UITable_2, if i change the cell selection of UITable, the edit affects the new selection in the UITable rather than previously selected one. Not sure if I put it well.
Here, while the cell with value 1 is selected, if I edit the value in UITable_2 and select value 2 in UITable during the edit, instead of saving the value 3 for the property associated with initial callback (app.a) before moving on, the code jumps to the new callback with 2 and assigns it to the property (app.b) associated with the new cell selected.
How can I ensure that a new cellselection callback completes the previous callback running before executing further??
Following is my complete code :
classdef basic_plot < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UITable matlab.ui.control.Table
UITable_2 matlab.ui.control.Table
properties (Access = private)
selectedCell % Description
a = {0 0};
b = {0 0};
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.UITable.Data =[1 2];
app.UITable_2.Data = [0 0];
app.selectedCell = 1;
% Cell selection callback: UITable
function UITableCellSelection(app, event)
indices = event.Indices;
switch indices(2)
case 1
app.UITable_2.Data =app.a;
case 2
app.UITable_2.Data =app.b;
% Cell edit callback: UITable_2
function UITable_2CellEdit(app, event)
indices = event.Indices;
newData = event.NewData;
switch app.selectedCell
case 1
switch indices(2)
case 1
app.a={newData app.a{2}};
case 2
app.a={app.a{1} newData};
case 2
switch indices(2)
case 1
app.b={newData app.b{2}};
case 2
app.b={app.b{1} newData};
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create UITable
app.UITable = uitable(app.UIFigure);
app.UITable.ColumnName = {'A'; 'B'};
app.UITable.RowName = {};
app.UITable.CellSelectionCallback = createCallbackFcn(app, @UITableCellSelection, true);
app.UITable.Position = [197 313 174 82];
% Create UITable_2
app.UITable_2 = uitable(app.UIFigure);
app.UITable_2.ColumnName = {'C'; 'D'};
app.UITable_2.RowName = {};
app.UITable_2.ColumnEditable = true;
app.UITable_2.CellEditCallback = createCallbackFcn(app, @UITable_2CellEdit, true);
app.UITable_2.Position = [197 203 174 77];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
% App creation and deletion
methods (Access = public)
% Construct app
function app = basic_plot
% Create UIFigure and components
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
  1 Comment
Biraj Khanal
Biraj Khanal on 19 Jan 2022
Edited: Biraj Khanal on 19 Jan 2022
For the beginner that I am, what solved it for me was having a drawnow as first line in the cellselection callback that emptied the queue.
This would however refresh all the figures (that is what I read from the doc) and finish the pending processes. If I have many figures and such editable texboxes, is there a way to either 1) specify which task in the queue to finish before moving on for the cellselection callback or 2) have this as a property of the table whose cell is being edited?
Interruptible and BusyAction do not help here.

Sign in to comment.

Answers (0)


Find more on Develop Apps Using App Designer 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!