MATLAB Answers

Custom function App Designer [Matlab] [App Designer]

151 views (last 30 days)
Robin L.
Robin L. on 14 Mar 2019
Edited: Robin L. on 14 Mar 2019
Hello !
I made a discovery in App Designer : it seems like "app" is optional when using custom functions :
methods (Access = private)
function add(app, a, b) % get both parameters BUT also app before !
disp(a + b);
function startupFcn(app)
app.add(app, 5, 6); % print 11
app.add(5, 6); % let's send 2 parameters (without app) / print also 11
Am I right ?
Is it advisable to send "app" first ?


Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 14 Mar 2019
No, the app object is not optional. You must pass it into the method in order to invoke the method.
What you're seeing is one of the two ways to invoke a method, dot notation versus function notation. See the section "Dot Notation vs. Function Notation" on this documentation page for a description of the specific cases where those two approaches to invoking a method can differ. [You can also use this to dynamically call a method whose name is stored in a string or char variable, as described in the "Referencing Names with Expressions—Dynamic Reference" section on that same documentation page.]
When you use dot notation, the object before the dot is passed into the method as the first input.

  1 Comment

Robin L.
Robin L. on 14 Mar 2019
Thank you so much Steven Lord ! 😃
But which one is better ?
add(app, 5, 6);
app.add(5, 6);

Sign in to comment.

More Answers (0)

Sign in to answer this question.