Why can use this function with only on input?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
fa wu
am 25 Jul. 2023
Kommentiert: fa wu
am 26 Jul. 2023
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 Kommentare
Akzeptierte Antwort
Steven Lord
am 25 Jul. 2023
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.]
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Class Introspection and Metadata finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!