1
votes

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?!

2
You must make your line 5 look more like your line 4, you need an = - Dan
I got that before, I just felt very bad for not seeing this myself in the first place.. grml Thanks again, I understood my mistake! - Lasse

2 Answers

4
votes

for j:n is bad syntax, you probably want for j = 1:n

4
votes

It works when you edit line 5 to: for j=1:n