How to make negative degree numbers positive while maintaining degree.
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kristin Aldridge
am 21 Okt. 2021
Bearbeitet: Walter Roberson
am 22 Okt. 2021
I'm trying to use
if avg_deg < 0, avg_deg = avg_deg+360; end
but it isn't working. I don't want to use abs because I want to rotate these negative degrees to their positive counterpart, but the line of code isn't doing anything at all.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 21 Okt. 2021
You can use logical indexing....
avg_deg = randi([-719 719], 1, 10)
mask = avg_deg < 0;
new_deg_version_1 = avg_deg;
new_deg_version_1(mask) = new_deg_version_1(mask) + 360
But I would suggest that mod() is more reliable, since it can handle angles < -360 and angles >= 360
new_deg_version_2 = mod(avg_deg, 360)
2 Kommentare
Walter Roberson
am 22 Okt. 2021
Bearbeitet: Walter Roberson
am 22 Okt. 2021
avg_deg = [randi([-719 719], 1, 5), -720, -360, 0, 360, 720]
new_deg_version_2 = mod(avg_deg, 360)
new_deg_version_3 = wrapTo360(avg_deg)
They differ on the treatment of positive multiples of 360.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Compiler SDK finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!