how to call a private function in private function?

10 ビュー (過去 30 日間)
Lv
Lv 2023 年 3 月 29 日
コメント済み: Lv 2023 年 4 月 6 日
APP DESIGNER methods (Access = private)
Inside the private function is the following statement to call another private function, ECEFtoECI
[B] = ECEFtoECI(app, A);
%When running, an error message is displayed indicating that the variable "app" cannot be recognized.
[B] = ECEFtoECI(JD(i), A);
%If this is the case, an error message is displayed indicating that ECEFtoECI cannot be found
  3 件のコメント
Lv
Lv 2023 年 3 月 30 日
thanks for your help, but following the above method still does not work, hint: cannot resolve the name“app.ECEFtoECI” in the line of function call
Does this have to do with the order in which the two private functions are defined?
chrisw23
chrisw23 2023 年 4 月 5 日
The calling function has to have app as an argument .
function callerOfECEFtoECI(app,others)
ret = app.ECEFtoECI()
end

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

採用された回答

Neha
Neha 2023 年 4 月 5 日
It is my understanding that you want to call a private function within a private function. Since I am not sure where exactly the object is being instantiated, there can be two scenarios where this will work.
Case 1: Calling the first private function from the constructor whose access level is public.
classdef MyClass
methods (Access = private)
function output1 = privateFunction1(obj)
output1 = obj.privateFunction2(A); % calling another private function
disp(output1);
end
function output2 = privateFunction2(obj,A)
output2 = A+35;
end
end
methods
function obj=MyClass()
obj.privateFunction1();
end
end
end
Case 2: Defining a public or a static function which can instantiate objects of the class (factory function).
classdef MyClass
methods (Access = private)
function output1 = privateFunction1(obj)
A=3;
output1 = obj.privateFunction2(A); % calling another private function
disp(output1);
end
function output2 = privateFunction2(obj,A)
output2 = A+35;
end
end
methods (Static)
function obj=createInstance(obj)
obj=MyClass();
obj.privateFunction1();
end
end
end
An instance of the class can be created by calling the static method.
obj=MyClass.createInstance();
You can refer to the method syntax documentation for more information about different types of methods and the syntax used to define them.
  1 件のコメント
Lv
Lv 2023 年 4 月 6 日
thanks for your help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by