How to turn a 64-bit matrix into a binary matrix

Asked by Nick Suttell about 9 hours ago
Latest activity Answered by Jan Simon about 6 hours ago

I have a matrix that is millions of rows long. It's a matrix of only one's and zero's. I want to turn the value type from 64-bit to binary so that I can store even more rows before my computer runs out of memory. How can I do this?

1 Comment

Jan Simon about 6 hours ago

Why is this bit array store in a 64 bit type? Please post more details, e.g. if it is signed or unsigned, if the neighboring bits are sorted columnwise or rowwise, If the number of rows or columns is a multiple of 8, if you want to modify the resulting array afterwards, etc.

Most likely it is a bad idea to store the bits in such a huge type, instead of choosing a bit-representation directly.

Nick Suttell

Tags

Products

No products are associated with this question.

3 Answers

Answer by Nick Suttell about 8 hours ago
Accepted answer

Basically I want to change each value in the matrix from 8 bytes to 1 bit

1 Comment

Jan Simon about 6 hours ago

Please do not post information belonging to the question as an answer and accepting an answer signals, that the problem is solved. Therefore I recommend, that you delete this answer, such that others will post further solutions.

Nick Suttell
Answer by Sean de Wolski about 8 hours ago

Use fwrite in conjunction with fopen/fclose to write the binary file with your data type.

doc fwrite

For more information.

0 Comments

Sean de Wolski
Answer by Jan Simon about 6 hours ago

A standard method for the transformation, but it depends on several details if this matches your problem:

x = uint64(rand(10, 8) > 0.5);  % Test data
y = uint8(x) * uint8([1;2;4;8;16;32;64;128])

0 Comments

Jan Simon

Contact us