matlab - 在每个 MATLAB 类中使用 "this"

标签 matlab

为什么在 MATLAB 的每个类中我都必须使用“this”?我认为在 C++ 中我不需要使用“this”,只要我愿意。在 MATLAB 中也是这样吗?

最佳答案

简而言之,您必须使用某种显式引用。

首先,与在 C++/C#/Java 中将其命名为 this 不同,您可以使用任何您想要的名称。 您必须使用显式调用的原因是 Matlab designers decision . 这个想法是为了支持对对象的 Matlab 向量操作,就好像它们是 结构。以下是上面链接的片段:

While languages with an implicit object parameter provide a "this" keyword to access the implicit object, they usually do not require you to access a property through "this". If MATLAB had implicit properties, the logical extension to array-based objects would be to index into nothing:
S = S + (k).Value;

编辑: 在 @AndrewJanke 的好评之后,我想补充一点,MATLAB 可以将 this 作为隐式引用,并且只强制在基于数组的对象的索引中使用它。尽管如此,MATLAB 设计者并没有选择这种方法。

关于matlab - 在每个 MATLAB 类中使用 "this",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8885109/

相关文章:

matlab - 取决于距离函数,matlab 中的 k-means 内存不足?

matlab - 从矩阵中提取正值和负值

matlab 打印 : 'Cannot create output file ' .\test.tif''

python - Python 或 C 中的 Matlab/Octave bwdist()

python - MAP@k计算

Matlab GPU计算

matlab - 通过排列避免 matlab 脚本中的 'for' 循环

matlab - 倍频程/Matlab : Adding new elements to a vector

matlab - 生成量化矩阵

image - 如何在 matlab 或其他方式中执行颜色量化