How to change angles to 0 to 180

48 ビュー (過去 30 日間)
TTA
TTA 2023 年 5 月 29 日
コメント済み: TTA 2023 年 5 月 30 日
I have an array of angles ranging from [-180, 180]
please I want to change to [0, 180], how can I do this?
I have tried this code below but it's giving me [90, 180]
Angles180 = @(a) rem(180+a, 360)-90;
Result = Angles180([-90, 0, 90])
please how can I do this?

採用された回答

Sam Chak
Sam Chak 2023 年 5 月 29 日
Hi @TTA
Are you looking for the conversion like this?
Angles180 = @(a) a/2 + 90;
Result1 = Angles180([-180, 0, 180])
Result1 = 1×3
0 90 180
Result2 = Angles180([-90, 0, 90])
Result2 = 1×3
45 90 135
  7 件のコメント
DGM
DGM 2023 年 5 月 29 日
編集済み: DGM 2023 年 5 月 29 日
So then should the answer be
[0 0 0 30 60 90]
or
[90 60 30 30 60 90]
or
[60 30 60 30 60 30]
or something else?
TTA
TTA 2023 年 5 月 30 日
Thanks for your effort

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

その他の回答 (2 件)

Image Analyst
Image Analyst 2023 年 5 月 29 日
How about just adding 180 to all angles less than 0, so for example -135 becomes +45 degrees.
mask = angles < 180;
angles(mask) = angles(mask) + 180; % Only add 180 to negative angles.
  2 件のコメント
DGM
DGM 2023 年 5 月 29 日
angles = mod(angles,180);
TTA
TTA 2023 年 5 月 30 日
編集済み: TTA 2023 年 5 月 30 日
@DGM you are right.
for example, To find the equivalent angle within the range of 0 to 90 degrees for -20 degrees, you can use the modulo operation and add multiples of 90 until the angle falls within the desired range.
Here's how you can calculate the equivalent angle:
  1. Take -20 modulo 360: -20 % 360 = 340. This step ensures the angle is within the range of 0 to 360 degrees.
  2. Since 340 is greater than 90, subtract multiples of 90 to bring it within the range of 0 to 90 degrees.
  • 340 - 270 = 70
Thanks

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


Image Analyst
Image Analyst 2023 年 5 月 29 日
You say "What I wanted to do is I want to put all the following angles in the first quadrant ([0,90] so the ones that are already within 0 t 90 does not change and the ones that are with negative can taken as absolute."
Well, what about this:
angles = abs(angles);
???
  1 件のコメント
TTA
TTA 2023 年 5 月 30 日
Thanks for your effort

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

カテゴリ

Help Center および File ExchangeTime Series Events についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by