MATLAB Answers


representing 8 bits per element

Asked by FIR
on 27 Dec 2012

In the previous post

walters comment

Remember, comp is representing binary, and so is 1 bit per element, whereas your original data is at least 8 bits per element.

now how to represent binary element as 8 bits per element

binary values are stored in comp

  1 Comment

Why wasn't this posted in that previous post then? Why did you start a whole new discussion?



No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 27 Dec 2012
 Accepted answer

Provided your vector comp is an exact multiple of 8 long:

x = comp;  %just to make the writing shorter
uint8( x(1:8:end) * 128 + x(2:8:end) * 64 + x(3:8:end) * 32 + x(4:8:end) * 16 + x(5:8:end) * 8 + x(6:8:end) * 4 + x(7:8:end) * 2 + x(8:8:end) )


on 27 Dec 2012

walter every time the size is varying

while length(x) ~= 8 * floor(length(x)/8)
  x(end+1) = 0;
on 27 Dec 2012

thanks a lot

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!