禁用MATLAB的隐式扩展 [英] Disable MATLAB's implicit expansion

查看:189
本文介绍了禁用MATLAB的隐式扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,在R2016b中,MATLAB中增加了一个功能,这在我所教的学校中引起了很多头痛.

Recently, in R2016b a feature was added to MATLAB, which is causing a lot of headaches in the school where I teach.

现在成功地执行了通常被认为是非法的或至少是幕后数学的如今的公式:

Nowadays formulae, which traditionally would be considered illegal or at least shady maths are executed successfully:

[1, 2] + [3, 4]'    -> [4, 5; 5, 6]
[1, 2]' + [3, 4, 5] -> [4, 5, 6; 5, 6, 7]

因此,将行向量添加到列向量被视为两个矩阵的相加,这可以通过重复向量达到合适的"维数来获得.在较旧的版本中,这会产生一条错误消息,通知您无法添加尺寸不同的矩阵.

So adding a row vector to a column vector is treated as an addition of two matrices one can get from repeating the vectors up to the "suitable" dimensions. In older versions this would have produced an error message informing that the addition of matrices with different dimensions is not possible.

我想问为什么有点宽泛,尽管如果您知道为什么,我很想知道.相反,我会问,是否可以禁用此功能?对于新手程序员来说,当常规数学似乎并不符合要求并且结果矩阵常常不被注意而导致后来才出错时,这是一个痛苦的世界.

I think asking why is a bit broad, although if you do know why, I'd love to know. Instead I will ask, is there a way to disable this functionality? To novice programmers this is a world of hurt when the conventional mathematics doesn't seem to be in line and the resulting matrix often goes unnoticed causing errors only later on.

我认为这不是MATLAB语法和行为的有用组成部分,因为它需要太多的解释,无法理解程序员的意图. repmat是有原因的,可以引入专用功能来满足此需求.

I can not see this being a useful part of MATLAB syntax and behavior, as it requires too much interpretation, reading into the intention of the programmer. repmat is there for a reason, and a dedicated function could be introduced to accommodate for the need of this thing.

推荐答案

此功能是在Matlab R2016b中引入的.在旧版本中,必须使用repmatbsxfun进行此扩展.较新的版本具有这种隐式扩展尺寸的功能,可以使计算向量化.

This feature was introduced in Matlab R2016b. In older versions, this expansion had to be done either with repmat or with bsxfun. Newer versions feature this implicit expansion of dimensions to vectorize the calculation.

在此博客文章中 MathWorks的Steve Eddins说:

In this blog post Steve Eddins, from MathWorks says that:

其他人认为,新的算子行为不足以线性代数表示法为基础.但是,与其将MATLAB视为纯粹的线性代数符号,不如将MATLAB视为矩阵和数组计算符号更为精确.

Other people thought that the new operator behavior was not sufficiently based on linear algebra notation. However, instead of thinking of MATLAB as a purely linear algebra notation, it is more accurate to think of MATLAB as being a matrix and array computation notation.

,并且在计算环境中确实有意义.我可以说,对于我的用途,这种隐式扩展确实确实使事情变得更加容易.

and it really does make sense in a computational context. I can say that for my uses, this implicit expansion does make things easier very often.

当然,从代数的角度来看,这没有任何意义.但是,如果您考虑一下,大多数计算机语言符号就没有意义.

Of course, seeing this from the point of view of algebra, it doesn't make sense. But if you think about it, most computer language notation wouldn't make sense.

由于这是该语言的一部分,因此应该无法禁用该功能(直到Yair Altman尝试这样做:P).

And since this is now part of the language, it shouldn't be possible to disable the feature (until Yair Altman tries to do so :P).

这篇关于禁用MATLAB的隐式扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆