Decimal to Binary Vector

5 ビュー (過去 30 日間)
Henok Mentamo
Henok Mentamo 2014 年 10 月 2 日
編集済み: Joseph Cheng 2014 年 10 月 2 日
Hi,
I am running Matlab R2013b and I am in need of an implementation to convert a decimal value to a binary vector and I saw that there is a matlab function decimalToBinaryVector that can do the job. But it seems that I dont have that function in my Matlab installation and it seems so that this functionality is in the Data Acquisition Toolbox which I dont have installed at the moment. How can I get this Toolbox and install it, and would that need a license and fee ( I now have a license from the workplace I use at my desk).

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2014 年 10 月 2 日
編集済み: Andrei Bobrov 2014 年 10 月 2 日
You should install Data Acquisition Toolbox, but have variant without Data Acquisition Toolbox. (idea by Jan Simon):
[ll,ll] = log2(max(a(:)));
out = rem(floor(a(:)*pow2(1-ll:0)),2);
here a - your decimal vector.
Or use function from MATLAB dec2bin:
out = dec2bin(a) - '0';

Joseph Cheng
Joseph Cheng 2014 年 10 月 2 日
編集済み: Joseph Cheng 2014 年 10 月 2 日
Have you tried the dec2bin() function built into matlab?
and then converting the string into a vector?
dec_x = randi(100,10,1)
bin_x = dec2bin(dec_x)
[num bits] = size(bin_x);
vect_x = str2num(bin_x(:));
vect_x = reshape(vect_x,num,bits);
  1 件のコメント
Iain
Iain 2014 年 10 月 2 日
he might want "typecast".

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by