필터 지우기
필터 지우기

Matlab if statements in physics

조회 수: 3 (최근 30일)
Momo
Momo 2018년 10월 18일
댓글: Momo 2018년 10월 19일
What does the condition mean in Matlab, where x and y are the displacement that measures from [-1,1]
if (abs(x)>=1)
x=sign(x);
end
if (abs(y)>=1)
y=sign(y);
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 10월 18일
The code is checking to see if the values are out of range and if so moving them to the boundary.
Momo
Momo 2018년 10월 19일
you mean x and y will equal 1 or -1 if their values are out of the range? as Mr. James said,right?

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

채택된 답변

James Tursa
James Tursa 2018년 10월 18일
편집: James Tursa 2018년 10월 18일
You can easily run the code to see that it clips the values outside of [-1,1] so that they stay in this range. But it appears there is a typo in the y code. This line
x=sign(y);
should probably be this instead (note the y on the lhs)
y = sign(y);
  댓글 수: 3
James Tursa
James Tursa 2018년 10월 18일
If x > 1, it will assign x = 1
If x <-1, it will assign x = -1
If x is between -1 and 1, it will leave x unchanged.
Same for y (as long as you fix the typo)
Momo
Momo 2018년 10월 18일
Thank you so much.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by