Is it possible to add a function in MATLAB that automatically wraps my data to a certain range of values?
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 27 Jun. 2009
Kommentiert: Elizabeth Reese
am 2 Jul. 2021
I am trying to plot angles and would like to have a function that automatically wraps my data to a certain range of values.
For example, if I want my angles to be in the range of between -180 to 180 degrees, then I would like the angle -220 degrees to be converted to 140 degrees.
Akzeptierte Antwort
MathWorks Support Team
am 2 Jul. 2021
Bearbeitet: MathWorks Support Team
am 2 Jul. 2021
The ability to automatically convert a number to wrap around a certain range of values is not available as a built-in function in MATLAB 7.6 (R2008a).
However, the following wrapping functions are available in the Mapping Toolbox:
WRAPTO2PI
WRAPTO360
WRAPTO180
WRAPTOPI
These functions make use of the MOD function and some logical operations to achieve the described conversion.
2 Kommentare
Adam Danz
am 28 Mär. 2021
> For example, if I want my angles to be in the range of between -180 to 180 degrees, then I would like the angle -220 degrees to be converted to 140 degrees.
wrapTo180(-220) % requires mapping toolbox
If you do not have access to the Mapping Toolbox or if you want to wrap numbers to an interval other than [-pi,pi], [0,2pi], [-180,180], or [0,360], you can use mod as suggested above or use wrapToInterval() on the file exchange.
Elizabeth Reese
am 2 Jul. 2021
Adam, thank you for pointing out the error. We've updated the answer to include your suggested change.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!