Let's start with a simple example:
We're having a button callback that calculates the numeric field value from two other numeric fields in the application.
function ButtonPushed(app, event) app.VariableAField1.Value = app.VariableBField2.Value*app.VariableCField3.Valueend
Then we call a helper function
function helpfun(app.VariableAField1.Value, app.VariableBField2.Value) x = app.VariableBField2.Value y = app.VariableAField1.Value; plot(x,y)end
If we had a bit more variables to pass in the helpfun, then input arguments in the helpfun would be quite long, and maybe unreadable.
The way that I did is to work with public properties, which I defined in the helper function and called within startupFcn. But, public properties operate in a similar way in Application (or am I wrong?) as the global variables operate in scripts, so that is what I am worried about.
Solution with properties:
function helpfun(app) % app.x and app.y have default values
% when the user updates respective field, callback will update x and y property values
plot(app.x,app.y)end
I would appreciate a light discussion on this question.
If this question should be on the pile of questions that are related to the usage of global variables, I welcome its confirmation and locking (with the suggestion of the common practice).
Thank you in advance.
Best Answer