Why does a variable not update on button push with uitable?
Mostrar comentarios más antiguos
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
Respuestas (1)
Walter Roberson
el 19 de Ag. de 2022
0 votos
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.
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!