How to call the function A in another function B under the static methods of the same APP Designer?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Bhanu Prakash
il 9 Ott 2023
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:
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!