21 Dec 2004
28 Dec 2004)
Compress large logical variables to one bit per element, instead of the usual 8.
function logicals = unpackLogicals(packedData)
% Decompresses a logical vector or array that was compressed using
% packLogicals. The size of the initial data must be known.
%By James R. Alaly
%JRA 9/14/04 - Vectorize for speed improvement.
%JRA 12/27/04 - Stores size vector in data struct. Iram Weinstein's idea.
% function logicals = unpackLogicals(data, siz)
error('unpackLogicals.m only works on data compressed using packLogicals.');
data = packedData.data;
siz = packedData.dataSize;
nUINTS = length(data(:));
nData = prod(siz);
if nUINTS * 8 < nData
error('Not enough data to construct vector/matrix of that size.');
%---Begin Vectorized Code
logicals = logical(zeros([1 nUINTS*8]));
logicals(i:8:end) = bitget(data, i);
logicals = logicals(1:nData);
logicals = reshape(logicals, siz);
%---Old, Unvectorized Code.
% logicals = logical(zeros([1 nData]));
% bitNumV = mod((1:nData)-1, 8) + 1;
% uintNumV = floor(((1:nData)-1)/8) + 1;
% for i=1:nData
% logicals(i) = bitget(data(uintNumV(i)), bitNumV(i));
% logicals = reshape(logicals, siz);