Matlab if statements in physics
1 回表示 (過去 30 日間)
古いコメントを表示
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
2018 年 10 月 18 日
The code is checking to see if the values are out of range and if so moving them to the boundary.
採用された回答
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
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)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!