MATLAB Answers

What is gray coding?

6 views (last 30 days)
Cantor Set
Cantor Set on 10 Mar 2020
Commented: Image Analyst on 15 Mar 2020
In the genetic toolbox of matlab, there is a function which is called bs2rv which takes random binary strings and map them to real numbers using either binary or gray coding.
I don't understand how bs2rv works, what exactly happens. I want to understand the algorithm of it, can someone help me understand it?
__________________________________________________________________________________________________
Purpose
binary string to real value conversion
Synopsis
Phen = bs2rv(Chrom, FieldD)
Description
Chrom=crtbp(Nind,Nvar) where crtbp generates a random matrix of element zero and one of size Nind rows and Nvar columns
Phen = bs2rv(Chrom, FieldD) decodes the binary representation of the
population, Chrom, into vectors of reals. The chromosomes are seen as
concatenated binary strings of given length, and decoded into real numbers over a
specified interval using either standard binary or Gray coding according to the
decoding matrix, FieldD. The resulting matrix, Phen, contains the
corresponding population phenotypes.
___________________________________________________________________
The matrix FieldD has the following structure:
The rows of the matrix are composed as follows:
len, a row vector containing the length of each substring in Chrom. Note that
sum(len) should equal length(Chrom).
lb and ub are row vectors containing the lower and upper bounds respectively for
each variable used.
code is a binary row vector indicating how each substring is decoded. Select
code(i) = 0 for standard binary and code(i) = 1 for Gray coding.

  1 Comment

Image Analyst
Image Analyst on 15 Mar 2020
Did you look at the definition in Wikipedia?

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!