1

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 = Commented Jul 12, 2013 at 12:24
  • 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! Commented Jul 12, 2013 at 12:39

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

I'm sorry if I annoyed anyone with this rather stupid mistake.. I'm a beginner and not good at proof-reading code, apperantly. :/
3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.