ga_bit2num.m
来自「基因演算法genetic algorthim的程式實現」· M 代码 · 共 20 行
M
20 行
function num = GA_bit2num(bit, range)% GA_BIT2NUM Conversion from bit string representations% to decimal numbers.% num= GA_BIT2NUM(BIT, RANGE) converts a bit string % representation BIT ( a 0-1vector) to a decimal number% , where RANGE is a two-element vector specifying the% range of the converted decimal number.%% For example:%% GA_bit2num([1 1 0 1], [0, 15])% GA_bit2num([0 1 1 0 0 0 1], [0, 127])% Roger Jang, 12-24-94integer = polyval(bit, 2); %[1 1 0 1]==> 1*2^3+1*2^2+0*2+1num = integer*((range(2)-range(1))/(2^length(bit)-1)) +... range(1);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?