Convert vector to single double number

5 Ansichten (letzte 30 Tage)
Terek Li
Terek Li am 26 Okt. 2016
Bearbeitet: Jan am 26 Okt. 2016
I have a vector [ 0 0 1 0 1 0 1] is there a quick way to convert it to a single number: 10101 ?

Akzeptierte Antwort

Jan
Jan am 26 Okt. 2016
Bearbeitet: Jan am 26 Okt. 2016
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.

Weitere Antworten (1)

KSSV
KSSV am 26 Okt. 2016
b =[ 0 0 1 0 1 0 1];
k = sprintf('%1d',b)
iwant=str2double(k) ;
  2 Kommentare
Terek Li
Terek Li am 26 Okt. 2016
yes this would work, but it is not fast enough for my need. Thanks a lot though!
KSSV
KSSV am 26 Okt. 2016
b =[ 0 0 1 0 1 0 1];
k = bin2dec(char(b+'0')) ;
dec2bin(k)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by