Skip to content

Instantly share code, notes, and snippets.

@Turux
Created January 9, 2018 16:22
Show Gist options
  • Save Turux/46ed2e41bfd7795b3cfbbadf0b568385 to your computer and use it in GitHub Desktop.
Save Turux/46ed2e41bfd7795b3cfbbadf0b568385 to your computer and use it in GitHub Desktop.
A MATLAB function that converts a 1D array from degrees to revolutions
function [ revs ] = deg2revs( deg )
% @Brief: A function that converts a 1D array from degrees to revolutions
% @Param: deg -> 1D array of angles expressed in degrees
% @Return: revs -> 1D array that counts how many revolutions have been
% completed. Starts from 1 for future grouping.
% A revolution
d = diff(deg);
revs = ones(length(deg),1);
for i = 1:(length(deg)-1)
if(d(i) < -90)
revs(i+1) = revs(i)+1;
else
revs(i+1) = revs(i);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment