View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Pack/Unpack Logicals

5.0 | 1 rating Rate this file 4 Downloads (last 30 days) File Size: 2.82 KB File ID: #6586 Version: 1.0
image thumbnail

Pack/Unpack Logicals



21 Dec 2004 (Updated )

Compress large logical variables to one bit per element, instead of the usual 8.

| Watch this File

File Information

MATLAB (6.5 at least) stores logical variables in memory as 8 bits per element, even though only one bit is required. This means a 512x512x100 logical mask takes up 25 MB of memory. By compressing this mask the same amount of data takes only 3MB.

A limitation is that compressed logicals are stored in a struct array, and cannot be operated on in a meaningful way without unpacking them. I use this compression to store many large masks in memory, and then I unpack them when I am ready to use them.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
30 Nov 2006 Hoang Hanh Luu Nguyen


Comment only
07 Jul 2005 Ryan White

Exactly what I needed. There is some overhead -- I was compressing a very large number of smaller logical arrays. Each one was 85 x85 and went from 7225 -> 1358 bytes.

Contact us