How to group and convert to decimal?

조회 수: 4 (최근 30일)
Sharen H
Sharen H 2013년 2월 4일
The output of r is 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1
I want to group every 8 digits and convert to decimal
Please help
  댓글 수: 4
Sharen H
Sharen H 2013년 2월 4일
r() function is a double value
Image Analyst
Image Analyst 2013년 2월 4일
편집: Image Analyst 2013년 2월 4일
You mean an "array" of doubles is returned by r(), like this [0, 0, 0, 1, 0, 1, 0, etc.], not just a single double like you implied. So, it's like what Azzi assumed.

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 4일
x=[ 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1]
x=num2str(x)
x(x==' ')=[];
y=reshape(x,[],8);
out=bin2dec(y)
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 4일
Ok, there is an error in reshape function
x=[ 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1]
x=num2str(x)
x(x==' ')=[];
y=reshape(x,8,[])';
out=bin2dec(y)
Sharen H
Sharen H 2013년 2월 4일
Thanks a lot....

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

추가 답변 (1개)

Jan
Jan 2013년 2월 4일
편집: Jan 2013년 2월 4일
Converting from a double vector to a string and back to a double inside bin2dec is not efficient. Better convert from binary to decimal values directly:
x = [ 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1];
d = 2 .^ (length(x)-1:-1:0) * x(:);

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by