필터 지우기
필터 지우기

Rounding off to odd multiples of 25

조회 수: 3 (최근 30일)
Utsav
Utsav 2015년 1월 28일
댓글: Utsav 2015년 1월 28일
variable X varies as 25:50:125875
A= "Enter a value of X"
I must round off the value of A (user input) to match certain X value.
I need if A = anything ending with 75 or 25 : aceept it if A = anything ending with values(26-49) : floor it to the value ending with 25, just before if A = anything ending with values(51-74) : ceiling it to the value ending with 75, just after

채택된 답변

Guillaume
Guillaume 2015년 1월 28일
It's fairly straightforward, subtract 25, divide by 50, round to nearest integer and then multiply back by 50 and readd the 25:
>>roundspecial = @(x) 25+50.*round((x-25)./50);
>>roundspecial(25)
ans =
25
>>rounspecial(26)
ans =
25
>>roundspecial(49)
ans =
25
>>roundspecial(50)
ans =
75
>>roundspecial(374)
ans =
375
  댓글 수: 1
Utsav
Utsav 2015년 1월 28일
I am so very thankful to you Sir for the kind help extended to me in this regard.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by