Why does a variable not update on button push with uitable?

I want a subroutine that will allow a user to input [x,y] coordinate data, press a button, and then return the user entered [x,y] data. Code below. I have tried with the 'defSensorPositionPushed' nested in the subroutine, and outside the subroutine. I unsupressed the return result on the button push and all is updating when function is executed. I'm missing something.
function [sensor] = platePos(numCh)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
fig = uifigure('Position',[500 500 300 500]);
posInitX = zeros(numCh,1);
t = table(posInitX,posInitX);
vars = {'X [in]','Y [in]'};
sensor = [posInitX,posInitX];
%varType = {'double','double'};
uit = uitable(fig,'Data',t,'Position',[10 10 280 400]);
set(uit,'ColumnEditable',logical([1 1]))
set(uit,'ColumnName',vars);
%set(uit,'VariableType',varType)
senBtn = uibutton(fig,'push',...
'Position',[10, 410, 280, 80],...
'Text','Define Sensor Position',...
'ButtonPushedFcn', @(senBtn,event) defSensorPositionPushed(senBtn,sensor,uit));
function [sensor] = defSensorPositionPushed(~,sensor,uit)
sensor = uit.Data
end
uiwait(fig);
end

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 8 月 19 日

0 投票

uibutton() creates a button control and then immediately continues execution in the routine that calls uicontrol. It does not wait for the user to push the button.
Callback functions mostly do not return values, because they are mostly run asynchronously at the time an action occurs, some time later after the control is created.
The kinds of callbacks that do return values are mostly used for position constraints, such as validation that a user interactive resize is to be permitted.

製品

リリース

R2022a

タグ

質問済み:

2022 年 8 月 19 日

回答済み:

2022 年 8 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by