You are doing two different operation sequences, so why the surprise that you get two different results?
First Case
>> 1:3 + [0 0 5]
ans =
1 2 3
>> 1: (3 + [0 0 5])
ans =
1 2 3
which is equivalent to
and thus is just
because the colon operator only uses the first element of the vector and ignore the rest: "If you specify nonscalar arrays, MATLAB interprets j:i:k as j(1):i(1):k(1)." Second Case
>> x = 1:3;
>> y = [0 0 5];
>> x+y
ans =
1 2 8
performs an element-wise addition on two vectors. Summary
Beginners often forget about operator precedence and to read the documentation...
Best Answer