恐怕这些语法甚至不是完全等价的,可以从以下示例中了解到:
>> f = fit( (1:3).', (2:2:6).' ,'poly1')
f =
Linear model Poly1:
f(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 2 (2, 2)
p2 = -6.784e-16 (-4.709e-14, 4.574e-14)
>> methods(f)
Methods for class cfit:
argnames cfit coeffvalues dependnames feval formula integrate numargs plot probnames setoptions
category coeffnames confint differentiate fitoptions indepnames islinear numcoeffs predint probvalues type
>> f.coeffvalues
Error using cfit/subsref (line 18)
The name 'coeffvalues' is not a coefficient or a problem parameter. You can only use dot notation to access the coefficients and problem parameters of a cfit or sfit, e.g.,
'f.p1'.
For the current fit, you can access these properties: p1, p2
You can get coefficient names and values either by name, e.g., p1 = f.p1, or by using the coeffnames or coeffvalues functions, e.g., names = coeffnames(f).
To use methods, use functional notation instead, e.g., plot(f).
>> coeffvalues(f)
ans =
2.0000 -0.0000
最重要的是:
要使用方法,请改用函数符号,例如 plot(f)。
现在假设我们是虐待狂,并且想要编写一个自己的行为类似的函数,进一步调查我们发现这cfit.coeffvalues
只是私有财产的吸气剂。现在,如果您仔细查看上面的错误,您会注意到它甚至没有出现在 中cfit.coeffvalues
,而是出现在cfit.subsref
!
综上所述,
从中我们可以根据经验得知,函数式符号直接传递给所讨论的方法,而 OOP 符号首先传递到subsref
类的可能被覆盖的方法。我想如果您想确保跳过任何 custom subsref
,请使用功能符号。