Why can use this function with only on input?

조회 수: 2 (최근 30일)
fa wu
fa wu 2023년 7월 25일
댓글: fa wu 2023년 7월 26일
Form this document ,need”Google Web Translation“
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);

채택된 답변

Steven Lord
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 CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by