MATLAB implementation of traversal method to generate cyclic code