how to divide the range of given integer number

조회 수: 8 (최근 30일)
Jimmy cho
Jimmy cho 2020년 12월 21일
댓글: Image Analyst 2020년 12월 21일
Hi guys,
Might the deadline of my problem isn't understandable, so here Im explaining my problem.
Im trying to do a range of given integer number between negative and positive (including zero and assume zero is positive ..this just assumption in my case) equally -meaning by equally that the negative number and positive numbers are equally in the two sides, this means :
GivenNumber is an integer parameter (assume it's bigger than 0 )
lets assume I have number 20, GivenNumber=20 so the output is the range : [-10:9] , implicitly the number of numbers/samples in the range [-10:9] are 20 which it's the Givennumber - you can easily see the negative numbers are equally to the positive numbers (including zero as my assumption as positive).
lets assume I have number 10, GivenNumber=10 so output is the range : [-5:4] , implicitly the number of numbers/samples in the range [-5:4] are 10 which it's the Givennumber - you can easily see the negative numbers are equally to the positive numbers (including zero as my assumption as positive).
lets assume I have number 30, GivenNumber=30 so output is the range : [-15:14] , implicitly the number of numbers/samples in the range [-15:14] are 30 which it's the Givennumber - you can easily see the negative numbers are equally to the positive numbers (including zero as my assumption as positive).
So how can I do a function in matlab to get as parameter : GivenNumber , the output is the range as explained above?
Appreciated !

답변 (1개)

Walter Roberson
Walter Roberson 2020년 12월 21일
for GivenNumber = [20 10 30 3 25]
Walters_Half = GivenNumber/2;
ceil(-Walters_Half) : ceil(Walters_Half)-1
end
ans = 1×20
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9
ans = 1×10
-5 -4 -3 -2 -1 0 1 2 3 4
ans = 1×30
-15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
ans = 1×3
-1 0 1
ans = 1×25
-12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12
  댓글 수: 2
Jimmy cho
Jimmy cho 2020년 12월 21일
THANKS!
Image Analyst
Image Analyst 2020년 12월 21일
Jimmy, you can thank answerers by clicking the "Accept this answer" link to give them reputation points. Thanks in advance.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by