Why can use this function with only on input?
2 次查看(过去 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!