MATLAB Answers

0

Question about column operator vectors

Asked by Anne Nguyen on 14 Oct 2019
Latest activity Edited by per isakson
on 14 Oct 2019
Why does vec = -1:-5 not output -1 -2 -3 -4 -5? Why does it say 1x0 empty double row vector? An explanation of this would be great. Thank you!

  0 Comments

Sign in to comment.

2 Answers

Answer by per isakson
on 14 Oct 2019
Edited by per isakson
on 14 Oct 2019
 Accepted Answer

x = j:k creates a unit-spaced vector x with elements [j,j+1,j+2,...,j+m] ...
x = j:i:k creates a regularly-spaced vector x using i as the increment ...
Thus the default value of the step, i, is +1 (one).
>> vec = -1:+1:-5
vec =
1×0 empty double row vector
and
>> vec = -1:+5
vec =
-1 0 1 2 3 4 5

  0 Comments

Sign in to comment.


Answer by Andrei Bobrov
on 14 Oct 2019

Use
vec = -1:-1:-5
or
vec = -(1:5)

  0 Comments

Sign in to comment.