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
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.
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!