I have an array which contains only 0s and 1s. Each data pt is getting saved as an 8 bit integer. How do I save it as a bit to save my memory space?

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 4월 11일

0 개 추천

in your case use logical array
a1 = randi([0 1],10));
a2 = logical(a1);

댓글 수: 1

Naved Patanwala
Naved Patanwala 2012년 4월 11일
Thanks for your suggestion.
That converts the array to logical but while saving, the memory size required remains the same. It saves '0' as '0000 0000' and 1 as '0000 0001'. Is there any way of saving bits individually because all I need is 0 and 1 which I can get from the last bit itself. That can save me a lot of memory space since my array has more than 10 lakhs of data pts.

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

Mohammad Reza Naderi
Mohammad Reza Naderi 2020년 7월 29일

0 개 추천

fwrite(fileID,A,precision,skip) Use fwrite for this work. https://www.mathworks.com/help/matlab/ref/fwrite.html#d120e398961

댓글 수: 1

Mohammad Reza Naderi
Mohammad Reza Naderi 2020년 7월 29일
If you want to save with specific precision use instead of precision ubitn

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

카테고리

제품

태그

질문:

2012년 4월 11일

댓글:

2020년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by