Logical Array Memory Allocation
조회 수: 19 (최근 30일)
이전 댓글 표시
Why does Matlab allocate one byte for every element in a logical array? Is there a way to make it one bit per element?
댓글 수: 0
채택된 답변
David Young
2011년 11월 28일
There's a trade-off between speed and memory use. Accessing and updating individual bits is slow, due to the underlying hardware architecture. MATLAB goes for a compromise that is good for most cases.
There is no 1-bit data type in MATLAB. If you really need to save memory as a top priority, you can store 8 bits to a byte using bitset and bitget operations on an array of integers.
EDIT 29 Nov 11
An update: I've just remembered bwpack and bwunpack in the Image Processing Toolbox. You could possibly make use of these.
댓글 수: 0
추가 답변 (1개)
Jan
2011년 11월 28일
Modern Matlab versions use a byte to store LOGICALs, as most other programming languages do. Storing the single bits is much slower, as David has explained already.
BTW, Matlab 5.3 used DOUBLEs (64 bits!) and set an extra flag to mark the variable as LOGICAL.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!