How to set extremum value of parameter?

조회 수: 1 (최근 30일)
Ani Asoyan
Ani Asoyan 2020년 5월 11일
댓글: Star Strider 2020년 5월 11일
I have a loop in which I change the value of a parameter.
how can I set maximum and minimum values for that parameter?
for example I want to set max(a)=5, min(a)=0

채택된 답변

Star Strider
Star Strider 2020년 5월 11일
To me, that the minimum is greater than the maximum does not make sense.
That aside, try this:
a = max(0, min(a,5))
Testing it:
a = -2:7
a = max(0, min(a,5))
produces:
a =
-2 -1 0 1 2 3 4 5 6 7
a =
0 0 0 1 2 3 4 5 5 5
Experiment to get the result you want.
.
  댓글 수: 3
Ani Asoyan
Ani Asoyan 2020년 5월 11일
it works ...thank you so much!
Star Strider
Star Strider 2020년 5월 11일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by