The function dec2gc converts a real positive numeric column vector to its gray code equivalent with a specified level of precision.
real_num = [34;78;123;7];%set of real numbers to be converted
N = 7;%precision level for gray coding
gray_code = dec2gc(real_num,N);
0 1 1 0 0 1 1
1 1 0 1 0 0 1
1 0 0 0 1 1 0
0 0 0 0 1 0 0
NOTE: N should be carefully chosen such that 2^N > max(dec)
I used it for building sequency of Hadamard matrix of order N.
function SeqOrd = GetSequency( N )
% N - [in] the order of Hadamard matrix
% SeqOrd - [out] the sequency, so that SeqOrd[i] is the sequency of row i
% 1. build a list of indexes 0..N-1
% 2. convert order of bits of each index
% 3. get the gray code value for each index ( that was converted)
% This gives the needed permutation with indexes range [0 .. N-1]
v = bitrevorder((0:N-1)'); % build list and reverse bit-order
SeqOrd = bitxor(v,bitshift(v,-1)); % find the gray-code
can we convert a matrix? yeh whatever, served the purpose for me!
Excellent solution. Thanks!
why not do like this:
not need to loop.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.