help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Binary decoding function problem


From: Kai Torben Ohlhus
Subject: Re: Binary decoding function problem
Date: Wed, 17 Jul 2013 13:45:27 +0200

On 17 July 2013 11:54, Doug Stewart <address@hidden> wrote:
On Wed, Jul 17, 2013 at 5:12 AM, bctn <address@hidden> wrote:
Hi Kai,

Of course.
Think that you have 10x20 random binary matrix, means that you have 10
chromosomes with 20 binary numbers. The code will be like that;
/x=randint(10,20)/
I want to decode it into integer number.

bin2dec can be used only for this usage;
/bin2dec("1 1 1 0 1 0 ..")/

This restricts my representation. E.g. i want to see and examine   /x(2,:)/
or all the chromosomes as a real value.

Best regards,


Is each item in your matrix a string or an integer???

--
DAS


With your example

octave:1> input = randint (10,20);

I get a 10x20 double matrix. Thus x(2,:) would result in a 1x20 double matrix. Now I guess you want this pattern of the second row "1001101..." to be seen as a bit pattern of some integer value. Try this one:

octave:2> x = reshape (dec2bin (input, 1), 10, 20);

This results in an 10x20 char matrix. Now you can read each row as a single integer number

octave:3> row_of_interest = x (2,:);
octave:4> val_of_interest = bin2dec (row_of_interest);

Best,
Kai

reply via email to

[Prev in Thread] Current Thread [Next in Thread]