필터 지우기
필터 지우기

Custom function App Designer [Matlab] [App Designer]

조회 수: 7 (최근 30일)
Robin L.
Robin L. 2019년 3월 14일
편집: Robin L. 2019년 3월 14일
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);
end
function startupFcn(app)
app.add(app, 5, 6); % print 11
app.add(5, 6); % let's send 2 parameters (without app) / print also 11
end
end
Am I right ?
Is it advisable to send "app" first ?
Robin

채택된 답변

Steven Lord
Steven Lord 2019년 3월 14일
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
Robin L.
Robin L. 2019년 3월 14일
편집: Robin L. 2019년 3월 14일
Thank you so much Steven Lord ! ?
But which one is better ?
add(app, 5, 6);
app.add(5, 6);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by