Display a degree heading as a compass heading rather than a absolute heading from the origin.
9 views (last 30 days)
Show older comments
title(sprintf('HMNZS AOTEAROA Ship motion in Sea state 6,\n Heading: %3.2f%c Runtime:%4.2f sec'...
, d , char(176), t), "Color", [1 1 1]); % Display Graph title with changeing data
I am wanting to display the heading of the vessel in a compass format. Currently, as it goes around in a circle the heading goes up to 758 degrees I believe there is a way to make it only display a heading from 0 to 359 deg.
I think it goes like this
C = Heading / 360
H = ??? % truncate CH to only leave digits after the decimal point
CH = H*360
Not sure how to truncate the whole numbers.
Thanks in advance
2 Comments
Accepted Answer
Adam Danz
on 2 Feb 2021
Edited: Adam Danz
on 2 Feb 2021
Otherwise,
Use mod() to wrap a value to [0,360] rather than rem()
theta = 758;
wrapped = mod(theta, 360);
Examples
mod(540, 360)
mod(-90, 360)
mod(360,360) % Note: returns 0
mod(360*2, 360) % Note: Returns 0
To keep 360 from changing to 0,
theta = 360;
mod(0, 360) + 360*(mod(theta, 360)==0 && theta>0)
theta = 360*2
mod(0, 360) + 360*(mod(theta, 360)==0 && theta>0)
Look what happens when you use rem
rem(-90,360) % oops!
0 Comments
More Answers (0)
See Also
Categories
Find more on 3-D Scene Control in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!