How to call the function A in another function B under the static methods of the same APP Designer?
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello! I'm learning how to design a MATLAB app with MATLAB APP Designer. I' ve written some static functions as the following examples, but I couldn't call the function "add1" in the funtion "test".
methods (Static)
function test(a, b)
c = add1(a, b); %Error: Undefined function 'add1' for input arguments of type 'double'.
fprintf('The results is %d', c);
end
function z = add1(x, y)
z = x + y;
end
end
I' m not familiar to the OOP. Could you guide me what mistakes I made and how to call the "add1" correctly in addition to nest it in "test"?
Thank you!
댓글 수: 0
채택된 답변
Bhanu Prakash
2023년 10월 9일
Hi Qiang,
I understand that you want to call the function ‘add1’ from a different function ‘test’, which is under the static methods of the same App Designer class.
One simpler way to accompish this is to define a class using the 'classdef' function in MATLAB, inheriting the base class 'matlab.apps.AppBase' to utilize the built-in functionality provided by App Designer.
Consider the following code:
classdef myApp < matlab.apps.AppBase
methods (Static)
function test(a, b)
c = myApp.add1(a, b);
fprintf('The result is %d\n', c);
end
function z = add1(x, y)
z = x + y;
end
end
end
where, 'myApp' is the name of the App Designer class. You can call the function 'add1' from the 'test' function as follows:
>>myApp.test(2,3)
The result is 5
For more information on the 'classdef' function, kindly refer to the following documentation:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!