transform a string with variable length to a matrix

David Bateman David.Bateman at motorola.com
Thu Aug 28 05:54:27 CDT 2008


Goebel, Juergen 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 ...
>
> Regards,
>
> Jürgen
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Help-octave mailing list
> Help-octave at octave.org
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>   
The de2bi function in the communications toolbox does what you want.. 
The advantage is that it handles matrices for speed. For example

octave:1> de2bi(0:15)
ans =

   0   0   0   0
   1   0   0   0
   0   1   0   0
   1   1   0   0
   0   0   1   0
   1   0   1   0
   0   1   1   0
   1   1   1   0
   0   0   0   1
   1   0   0   1
   0   1   0   1
   1   1   0   1
   0   0   1   1
   1   0   1   1
   0   1   1   1
   1   1   1   1

octave:2> de2bi([0:15],"left-msb")
ans =

   0   0   0   0
   0   0   0   1
   0   0   1   0
   0   0   1   1
   0   1   0   0
   0   1   0   1
   0   1   1   0
   0   1   1   1
   1   0   0   0
   1   0   0   1
   1   0   1   0
   1   0   1   1
   1   1   0   0
   1   1   0   1
   1   1   1   0
   1   1   1   1


D.


-- 
David Bateman                                David.Bateman at motorola.com
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



More information about the Help-octave mailing list