フィルターのクリア

How to set extremum value of parameter?

2 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by