什么是语法错误“错误:不平衡或意外的括号或括号。”?

时间:2017-04-17 20:43:04

标签: matlab syntax-error octave

以下代码会产生错误

n=4; 
p=3; 
x =-(pi./2); 
y=-(pi./2);
z=-(pi./2); 

%Now, define the matrix v_k  
v_k = [sin(x).*sin(y).*sin(z), ...
    1-(1-cos(x))(sin(y).^2.*sin(z).^2), ...
    -(1-cos(x))(sin(y).^2.*sin(z).*cos(z)), ...
    -(1-cos(x))(sin(y).*sin(z).*cos(y)); ...
    sin(x).*sin(y).*cos(z), ...
    -(1-cos(x))(sin(y).^2.*sin(z).*cos(z)), ...
    1-(1-cos(x))(sin(y).^2.*cos(z).^2), ...
    -(1-cos(x))(sin(y).*cos(y).*cos(z)); ...
    sin(x).*cos(y), ...
    -(1-cos(x))(sin(y).*sin(z).*cos(y)), ...
    -(1-cos(x))(sin(y).*cos(y).*cos(z)), ...
    1-(1-cos(x))(cos(y).^2); ...
    cos(x), ...
    -sin(x).*sin((y).*sin(z),...
    -sin(x).*sin(y).*cos(z),...
    -sin(x).*cos(y)];

显示的错误是:

Error: File: test.m Line: 9 Column: 17 Unbalanced or unexpected parenthesis or bracket.

或者,如果从命令窗口运行

v_k = [sin(x).*sin(y).*sin(z), ...
    1-(1-cos(x))(sin(y).^2.*sin(z).^2)]
     1-(1-cos(x))(sin(y).^2.*sin(z).^2)]
                 ↑
Error: Unbalanced or unexpected parenthesis or bracket.

1 个答案:

答案 0 :(得分:2)

看起来你错过了一个右括号,至少在你的.*sin((y).*sin(z),之间的*中缺少)((或其他运算符)的倒数第二行几行。在MATLAB中,(A)(B)不是A*B