How to set extremum value of parameter?

1 Ansicht (letzte 30 Tage)
Ani Asoyan
Ani Asoyan am 11 Mai 2020
Kommentiert: Star Strider am 11 Mai 2020
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

Akzeptierte Antwort

Star Strider
Star Strider am 11 Mai 2020
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 Kommentare
Ani Asoyan
Ani Asoyan am 11 Mai 2020
it works ...thank you so much!
Star Strider
Star Strider am 11 Mai 2020
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by