From: Felipe Uribe on
"Yanfei " <yanf_jiang(a)yahoo.com> wrote in message <h3npa6$jvr$1(a)fred.mathworks.com>...
> Thanks guys, I have that toolbox, it seems de2bi is a little bit faster than dec2bin-48 or '0'; problem solved. I really appreciate your help, guys.
>
>
> "Yanfei " <yanf_jiang(a)yahoo.com> wrote in message <h3ncsl$sdp$1(a)fred.mathworks.com>...
> > Hi everyone,
> >
> > Do you know how to convert each element of a vector from decimal to binary. bitget and dec2binvec only work for single number. here is the example:
> >
> > vector = [ 1 2 3 4 5 6];
> > what I want is
> > [0 0 0 0 0 0 0 1
> > 0 0 0 0 0 0 1 0
> > 0 0 0 0 0 0 1 1
> > 0 0 0 0 0 1 0 0
> > 0 0 0 0 0 1 0 1
> > 0 0 0 0 0 1 1 0]
> >
> > Thanks

You can use this code, is longer than the previous one, but it may be useful:

vector = [ 1 2 3 4 5 6];
n=length(vector);
bin_matrix=zeros(n,8);
for i=1:n
bin_matrix(i,:)=dec2binvec(vector(i),8);
end
M = fliplr(bin_matrix)

Felipe
 | 
Pages: 1
Prev: Getting Video Codecs to work
Next: hello