# How to solve a simple if loop

2 ビュー (過去 30 日間)
Patty Oikawa 2012 年 12 月 15 日
I have a variable that ranges between 0.01 and 0.62. I want to find all values of that single vector that exceed 0.59 and make them equal 0.59.
I tried running an if statement and it runs with no errors, but the variable does not change (there are still #s in that variable that are greater than 0.6). the code I have now that doesn't work:
if Theta>0.59
then (Theta=0.59);
end
What am I doing wrong?

サインインしてコメントする。

### 採用された回答

Matt Fig 2012 年 12 月 15 日

1. There is no such thing as an IF loop.
2. IF statements do not filter elements out of an array.
3. MATLAB does not use a THEN keyword.
Theta = min(Theta,.59);
You could also do it this way:
Theta(Theta>.59) = .59;
##### 2 件のコメント表示非表示 1 件の古いコメント
Matt Fig 2012 年 12 月 15 日
Good catch, Walter.

サインインしてコメントする。

### カテゴリ

Find more on Whos in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by