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!
b =[ 0 0 1 0 1 0 1];
k = bin2dec(char(b+'0')) ;
dec2bin(k)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating 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