フィルターのクリア

How to call the function A in another function B under the static methods of the same APP Designer?

7 ビュー (過去 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!

採用された回答

Bhanu Prakash
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:
  1 件のコメント
Qiang Fu
Qiang Fu 2023 年 10 月 10 日
Dear friend,
Thank you for your help! I have practiced it in my app project and it works well.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFortran with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by