From: Naftali Herscovici on
Hello,

I need to generate strings, 4 characters long that include either '0' (zeros) or '1' ones.

I do:

for m=0:15 '(4 bits)
q=dec2bin(m);
s1=substr(q, 1, 1);
s2=substr(q, 2, 1);
s3=substr(q, 3, 1);
s4=substr(q, 4, 1);
end
substr is the equivalent of mid$(a$,..) in visual basic. Is there any similar function in matlab?
since by default, for some m, q does not include the leading zeros, it does not work.

Any ideas about how to make q 4 character long and retain the leading zeros?

Thanks

Tuli
From: Oleg Komarov on
"Naftali Herscovici" <tuli01(a)hotmail.com> wrote in message <hleavo$lhe$1(a)fred.mathworks.com>...
> Hello,
>
> I need to generate strings, 4 characters long that include either '0' (zeros) or '1' ones.
>
> I do:
>
> for m=0:15 '(4 bits)
> q=dec2bin(m);
> s1=substr(q, 1, 1);
> s2=substr(q, 2, 1);
> s3=substr(q, 3, 1);
> s4=substr(q, 4, 1);
> end
> substr is the equivalent of mid$(a$,..) in visual basic. Is there any similar function in matlab?
> since by default, for some m, q does not include the leading zeros, it does not work.
>
> Any ideas about how to make q 4 character long and retain the leading zeros?
>
> Thanks
>
> Tuli
q = dec2bin(0:15);
num2str(q) % transform in char
Oleg