How to retrieve intermediate variables from a callback function?

3 次查看(过去 30 天)
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

采纳的回答

Adam
Adam 2016-12-16
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by