For example, the distance between 15 deg and 350 deg is
>> rad2deg(circ_dist(deg2rad(15), deg2rad(350)))
ans =
25
>> rad2deg(circ_dist(deg2rad(350), deg2rad(15)))
ans =
-25
If you have Matlab's Robotics Systems Toolbox, you could use angdiff(). Note the opposite sign of the outputs compared to circ_dist(). >> rad2deg(angdiff(deg2rad(15),deg2rad(350)))
ans =
-25
>> rad2deg(angdiff(deg2rad(350),deg2rad(15)))
ans =
25
Compare these to Matlab's wrapTo360() which only wraps values between [0,360] so 350-15 would not indicate the closest circular distance. >> wrapTo360(15-350)
ans =
25
>> wrapTo360(350-15)
ans =
335
Best Answer