Scale any angle between [0, 180] and [0,-181] degrees

8 ビュー (過去 30 日間)
Andrew Poissant
Andrew Poissant 2017 年 11 月 27 日
回答済み: Geoff Hayes 2017 年 11 月 27 日
How do I scale any angle that I get to be between 0 and +/-180 degrees? So lets say I have 750 degrees, I want the output to be 30. However, if I have 950, I want the output to be -130.

採用された回答

Geoff Hayes
Geoff Hayes 2017 年 11 月 27 日
Andrew - suppose you have your angle whether it is 750 or 950. So long as the angle is greater than 180 degrees, then just subtract 360 from it. This will ensure that your "scaled" angle is in the interval [-179, 180] degrees. For example,
angle = 750;
while angle > 180
angle = angle - 360;
end
The above will give you the "scaled" angle of 30 degrees. Replace with 950 and the answer will be -130.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 11 月 27 日
temp = mod(angle, 360);
mask = temp > 180;
temp(mask) = 180 - temp(mask);

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by