File Exchange

image thumbnail

Gray Code Manipulation

version 1.0 (7.48 KB) by

Generate Gray Codes and convert them to integers.



No License

Gray Codes are used for Goniometers,
a Hamiltonian Circuit on a Hypercube,
and for searches and optimizations
of functions of a few variables each
of which takes a few discrete values.
For details see file GrayCode.txt
that is included with this submission.

Comments and Ratings (4)

it really help! thanks! :)

Good Job!

You can get at least a 5-10x speedup in the integer routines by changing the routines to cast floats to the correct uint** type and replacing the fix(0.5*k) with bitshift(k, -1).

For the 10-12 bit long codes I'm working with, graytest(10) and (12), the ratio goes from ~ 400 to 1500/2800 upon changing the routine, including the appropriate type checking and casting.

Also, the fix() call in int2gray() at least doesn't play nicely with a uint** passed in. I haven't checked gray2int().

That said, I've gotten great use out of (my modified versions of) these routines. Thanks for providing them.

my name is chris

great stufff ;)

MATLAB Release
MATLAB 5.2 (R10)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today