Borrar filtros
Borrar filtros

Converting a decimal matrix to binary in GA

1 visualización (últimos 30 días)
Hi,
I have a big problem in a multivariable function for Genetic Algorithms, I can't convert my decimal matrix to binary correctly it contains a signed and fractional numbers between -3 ,3.I need to finish the secript in 2 days Help please.
xx=-3+6*rand(10,1);
Thank You.

Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de En. de 2024
Editada: Walter Roberson el 3 de En. de 2024
typecast() the decimal matrix to 'uint64', and then use bitget() to fetch the individual bits.
Example,
format long g
Num = -sqrt(5)
Num =
-2.23606797749979
as64 = typecast(Num, 'uint64')
as64 = uint64
13835589633109914792
%checks to be sure that we are working with the same number
num2hex(Num)
ans = 'c001e3779b97f4a8'
dec2hex(as64)
ans = 'C001E3779B97F4A8'
%checks passed.
%get the bits
bits = bitget(as64, 64:-1:1)
bits = 1×64
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 0 1 1 1 0 1
Chances are quite high that this technically correct solution is useless to you.
I suggest that you post a small selection of numbers and the corresponding binary that you would like to see as a result.

Más respuestas (0)

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by