Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8068309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:38:01+00:00 2026-06-05T12:38:01+00:00

I want to store a vector of integers (uint8) as (space-)efficiently as possible in

  • 0

I want to store a vector of integers (uint8) as (space-)efficiently as possible in MATLAB. So far, I am using arithenco to encode the vector:

bits = arithenco(z, counts);

The good thing is that it returns a vectors of bits. The bad thing is that the bits are stored in doubles. This means that the returned vector is about 64 times as large as the original uint8 vector, while the whole idea was to make the thing smaller.

So is there an easy (and runtime-efficient) way to encode those pseudo-bits so that I actually get a space improvement?

The only solution I’ve come up with yet is to use bitset to store all those bits in a vector of, say, uint32 again, but this seems to be cumbersome and not very fast as I will have to loop over the whole bits vector explicitly.

Note: I can not use the Java API for this, otherwise this would have been relatively easy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:38:03+00:00Added an answer on June 5, 2026 at 12:38 pm

    Similar to your solution, but using core MATLAB functions only:

    %# some random sequence of bits
    bits = rand(123,1) > 0.5;
    
    %# reshape each 8 bits as a column (with zero-padding if necessary)
    numBits = numel(bits);
    bits8 = false(8, ceil(numBits/8));
    bits8(1:numBits) = bits(:);
    
    %# convert each column to uint8
    bits_packed = uint8( bin2dec(char(bits8'+'0')) );
    

    Compare the sizes:

    >> whos bits bits_packed
      Name               Size            Bytes  Class      Attributes
    
      bits             123x1               123  logical              
      bits_packed       16x1                16  uint8          
    

    To unpack/recover the original bits:

    %# unpack
    b = logical(dec2bin(bits_packed)' - '0');
    b = b(:);
    
    %# sanity check
    isequal(bits, b(1:numBits))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a comma separated integers and I want to store them in std::vector<int>
I want to store integers with greater than 64 bits in length. Number of
I want to store a very long string in database using php. The size
I am using a datatype of std::vector<std::vector<T> > to store a 2D matrix/array. I
Let's say I want to store a vector of LPD3DXSPRITE objects. The line to
I want to store a list of objects in an std::vector , but the
I have a string which i then want to store in a vector string
Say want to store the following: typedef std::function<void(int)> MyFunctionDecl; ..in a collection: typedef std::vector<MyFunctionDecl>
I'm using std::shared_ptr<T> for a lot of different types. Since I want to store
I want to store an object with a number vector as key in some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.