[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: transform a string with variable length to a matrix
From: |
Goebel, Juergen |
Subject: |
RE: transform a string with variable length to a matrix |
Date: |
Thu, 28 Aug 2008 12:33:18 +0200 |
> Benjamin Lindner wrote:
> If I interpret your problem correctly, then you want to transfer a
> number into a vector containing the binary representation.
You're absolutely right.
> You can do this without the intermediate string conversion by
>
> A = 9;
> Nbits = ceil(log2(A));
> bitmap = uint32( 2.^[0:Nbits-1] );
> M = double(bitand(A,bitmap) ~= 0);
That's ok (and something like this was my first attempt, too),
but I think using an internal function is significantly faster
(without having measured it).
Thanks a lot,
Jürgen