这些是更多的猜测,而不是一个答案。
命令或语句分隔符
To enter more than one MATLAB command or statement on the same line,
separate each command or statement with a comma:
for k = 1:10, sum(A(k)), end
在线
B = {1,2,3,}
因此一个声明在3之后是预期的,只有},这意味着单元格数组的结尾,一个有效的语句。
分号有三个官方用法:
阵列行分隔符
When used within square brackets to create a new array or concatenate
existing arrays, the semicolon creates a new row in the array:
A = [5, 8; 3, 4]
输出抑制
When placed at the end of a command, the semicolon tells MATLAB not to
display any output from that command. In this example, MATLAB does not
display the resulting 100-by-100 matrix:
A = ones(100, 100);
命令或语句分隔符
Like the comma operator, you can enter more than one MATLAB command on
a line by separating each command with a semicolon. MATLAB suppresses
output for those commands terminated with a semicolon, and displays
the output for commands terminated with a comma.
In this example, assignments to variables A and C are terminated with
a semicolon, and thus do not display. Because the assignment to B is
comma-terminated, the output of this one command is displayed:
A = 12.5; B = 42.7, C = 1.25;
所以在线
x = {1,2,3,;5,6,7}
它遵循有效的语句Array Row Separator after 3,。之后,预计会有新的声明,在这种情况下是双重的5.有效。
现在考虑一下
x = {1,2,3,;;;;4,5,6;;;}
如上所述,3之后,遵循语句Array Row Separator,之后的语句可能是从C ++中的一些基础程序核心借用的null statement – NOP,这基本上意味着:什么都不做。 3之后在下一个声明之前,遵循三次“不做任何事情”。没有意义,因为Matlab告诉你:额外的分号是不必要的。 – 但有效。
它也允许你无意义的事情,如:
if true
;
end
这也是为什么这个原因
C = {1,2,3,,,}
返回一个错误,因为逗号不是一个空的语句,而是在第一个逗号后面有一个预期的语句。
底线:看起来很奇怪,但实际上对我来说似乎是逻辑,因为Matlab在内部使用了大量的C-Code,并考虑到null语句,所提到的一切都是有效的语法。
其他langages呢?
Python中使用的x = [1,2,3,;;; 4,5,6 ;;;]中的分号是无效的,即使在预期的Matlab克隆numpy中,除非包含在这个不常见的语法a = np中。矩阵( ‘1,2,3; 4,5,6’)。
a = np.matrix('1,2,3,;;;;4,5,6;;;')
也会抛出一个错误,就像在任何情况下都被解释为数组行分隔符,这使编译器抱怨不一致的行大小。
然而,
x = [1,2,3,]
在Python和IronPython中也是有效的语法,就像07年2月提到的VBScript和Lua一样。这些语言有什么共同点?它们都是(或多或少)在运行时解释的脚本语言。这不只是Matlab。因此,OP的兴奋仍然没有原因。