Why can use this function with only on input?
1 回表示 (過去 30 日間)
古いコメントを表示
there is two class AcListSuper AcListNonSub
AcListSuper.m
classdef AcListSuper
methods (Access = {?AcListNonSub})
function obj = m1(obj)
disp ('Method m1 called')
end
end
end
AcListNonSub.m
classdef AcListNonSub
methods
function obj = nonSub1(obj,AcListSuper_Obj)
% Call m1 on AcListSuper class
AcListSuper_Obj.m1;
end
function obj = m1(obj)
% Define a method named m1
disp(['Method m1 defined by ',class(obj)])
end
end
end
creat two object a b
a = AcListSuper;
b = AcListNonSub;
When I run this,program will call" function obj = nonSub1(obj,AcListSuper_Obj)" ,but this function has two input,“b.nonSub1(a);" just give one input! function "nonSub1" has no input test like "nargin" ………… ,but there is no erro waring!
I run this program and tracking to "AcListNonSub.nonSub1",I found "obj" class is "AcListNonSub" , "AcListSuper_Obj" class is "AcListSuper" .
Why? b.nonSub1(a) just give one input , AcListNonSub.nonSub1 automatically assigned two classes to “obj” and “AcListSuper_Obj” ?
According to what rules does MATLAB assign input parameters?
b.nonSub1(a);
0 件のコメント
採用された回答
Steven Lord
2023 年 7 月 25 日
b.nonSub1(a) just give one input
Incorrect. As shown in the "Dot and Function Syntaxes" section on this documentation page this is not equivalent to calling nonSub1 with just a as input. It is equivalent to nonSub1(b, a) in almost all circumstances. [The case where it doesn't is if the class of a lists the class of b as one of its InferiorClasses, as discussed on this documentation page and the "Determining Which Method Is Invoked" section on the first documentation page to which I linked.]
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Construct and Work with Object Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!