How to solve a simple if loop

조회 수: 1 (최근 30일)
Patty Oikawa
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
Matt Fig 2012년 12월 15일
편집: 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.
Use this instead:
Theta = min(Theta,.59);
You could also do it this way:
Theta(Theta>.59) = .59;
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 12월 15일
4. Assignment statements cannot be with ().
Matt Fig
Matt Fig 2012년 12월 15일
Good catch, Walter.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by