Making a vector from a Number

조회 수: 1 (최근 30일)
Chris Dan
Chris Dan 2020년 7월 4일
댓글: John D'Errico 2020년 7월 4일
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
John D'Errico
John D'Errico 2020년 7월 4일
Do you know how to use the colon operator? Have you read any getting started tutorials? If not, then why not? Colon is almost the first thing you would lean.
So, do you know how to use colon to create a vector? Perhaps you might try reading the help for colon. See what it says.
Chris Dan
Chris Dan 2020년 7월 4일
Thanks, got it :)

댓글을 달려면 로그인하십시오.

답변 (1개)

Chris Dan
Chris Dan 2020년 7월 4일
r = 5
rr= -r:r
size(x,2)
  댓글 수: 1
John D'Errico
John D'Errico 2020년 7월 4일
+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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by