简体   繁体   English

非常简单的MatlabR2011b脚本中出乎意料的MATLAB运算符

[英]Unexpected MATLAB operator in very simple MatlabR2011b script

Very simple tutorial-script, that doesn't run on my MATLAB: 非常简单的教程脚本,无法在我的MATLAB上运行:

function y=test1(A)
[m,n]=size(A);
y = 0;
for i=1:m
    for j:n
        y=y+A(i,j);
    end
end

Saved in test1.m. 保存在test1.m。 When I call it with 当我打电话给

A = [ 1 2; 3 4];
s = test1(A)

It gives me: 它给了我:

Error: File: test1.m Line: 5 Column: 10 Unexpected MATLAB operator. 错误:文件:test1.m行:5列:10意外的MATLAB运算符。

reffering to the n, which MATLAB also in line 5 points out as: 相对于n,MATLAB在第5行中也指出:

Parse Error at ':': might be invalid MATLAB syntax. “:”处的解析错误:可能是无效的MATLAB语法。 In line two it also gives notice, that n might be unused.. 在第二行中,它也发出了通知,即n可能未被使用。

How do I make sense of this, syntax looks correct to me?! 我如何理解这一点,语法对我来说正确吗?

for j:n是错误的语法,您可能想要for j = 1:n

当您将第5行编辑为:对于j = 1:n时,它起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM