How to retrieve intermediate variables from a callback function?

1 visualización (últimos 30 días)
Hi,
I was working on the app designer in matlab which has 3 buttons. For the first two buttons it prints the entrance time and exit time as sprint variables which are extracted from the clock function once the button is clicked. I want to use the two variables when the clock function is used to subtract them when the third button is clicked.
%Button1 button pushed function
function Button1ButtonPushed(app)
A1 = clock;
fix(A1)
E1 = sprintf('\n%2.0f:%2.0f:%2.0f',A1(4),A1(5),A1(6));
app.Enter1.Value = E1;
end
% Button2 button pushed function
function Button2ButtonPushed(app)
B1 = clock;
fix(B1)
S1 = sprintf('\n%2.0f:%2.0f:%2.0f',B1(4),B1(5),B1(6));
app.Exit1.Value = S1;
end
% Button3 button pushed function
function Button3ButtonPushed(app)
T = etime(B1,A1);
end

Respuesta aceptada

Adam
Adam el 16 de Dic. de 2016
app should be an object of a class so it has properties. You can add your own properties and then you have access to these anywhere where you have the app available.
e.g.
properties
someProp;
end
In your case though you seem to already have what you want stored in app.Exit1.Value so you can just access this in your 3rd callback.
If it is something else you want to store then you can just do so as e.g.
app.someProp = 7;
and then access this in any other callback.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by