help-octave
[Top][All Lists]
Advanced

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

Re: transform a string with variable length to a matrix


From: Jaroslav Hajek
Subject: Re: transform a string with variable length to a matrix
Date: Thu, 28 Aug 2008 12:35:19 +0200

On Thu, Aug 28, 2008 at 9:34 AM, Goebel, Juergen
<address@hidden> wrote:
> Hi,
>
> Using dec2bin I transform a decimal number to a binary number
> with an a priori unknown number of digits. But the next step
> offers a little problem for me: I have to transform the resulting
> string to a matrix of ones and zeros. Trying a bit with str2mat
> like str2mat([a(1);a(2);a(3)] wasn't successful 'cause the
> number of digits is variable.
>
> I'm sure some wizard can tell me what I have to do ...

This is possible via mat2cell. But getting the bit representation is
actually simpler, just do:
nb = floor (log2 (x)) + 1;
b = bitget (x, nb:-1:1);

best,

-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

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