Very simple tutorial-script, that doesn't run on my 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. 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.
reffering to the n, which MATLAB also in line 5 points out as:
Parse Error at ':': might be invalid MATLAB syntax. In line two it also gives notice, that n might be unused..
How do I make sense of this, syntax looks correct to me?!
for j:n
是错误的语法,您可能想要for j = 1:n
当您将第5行编辑为:对于j = 1:n时,它起作用
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.