Convert vector to single double number

I have a vector [ 0 0 1 0 1 0 1] is there a quick way to convert it to a single number: 10101 ?

 採用された回答

Jan
Jan 2016 年 10 月 26 日
編集済み: Jan 2016 年 10 月 26 日

1 投票

Does "quick" means fast or easy?
x = [0 0 1 0 1 0 1];
p = flipud([1; cumprod(repmat(10, size(x, 2) - 1, 1))]);
y = x * p;
This is fast, but it may look complicated on the first sight.

その他の回答 (1 件)

KSSV
KSSV 2016 年 10 月 26 日

0 投票

b =[ 0 0 1 0 1 0 1];
k = sprintf('%1d',b)
iwant=str2double(k) ;

2 件のコメント

Terek Li
Terek Li 2016 年 10 月 26 日
yes this would work, but it is not fast enough for my need. Thanks a lot though!
KSSV
KSSV 2016 年 10 月 26 日
b =[ 0 0 1 0 1 0 1];
k = bin2dec(char(b+'0')) ;
dec2bin(k)

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2016 年 10 月 26 日

編集済み:

Jan
2016 年 10 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by