Making a vector from a Number

1 view (last 30 days)
hamzah khan
hamzah khan on 4 Jul 2020
Commented: John D'Errico on 4 Jul 2020
Hello,
I am taking input a number as a positive integer and want to make a vector from it. The vector would contain real numbers,
for example
r =2
Now, I want to make a vector from -2 till 2. it should be
rr = [-2 -1 0 1 2]
If we have
r =5
then the vector should be from -5 till 5.
rr = [-5 -4 -3 -2 -1 0 1 2 3 4 5]
Does anyone know how to do that?
  2 Comments
hamzah khan
hamzah khan on 4 Jul 2020
Thanks, got it :)

Sign in to comment.

Answers (1)

hamzah khan
hamzah khan on 4 Jul 2020
r = 5
rr= -r:r
size(x,2)
  1 Comment
John D'Errico
John D'Errico on 4 Jul 2020
+1. That really is the best solution, where you found it yourself. That is because it means you had to look at the help and possibly make a mistake or two, or not. Getting your hands dirty in MATLAB is the way to learn.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by