>> f_dbl = 1 ;
>> f_log = true ;
>> whos
Name Size Bytes Class Attributes
f_dbl 1x1 8 double
f_log 1x1 1 logical
Logicals are stored on one byte each. You can manage flags stored as bits in integer variables, but this is likely to induce some overhead due to bits manipulation.
Now it's faster to store logicals than doubles, because it takes 8 times less room in memory; also, accessing them 8 logicals at a time is faster than 1 double at a time..
>> tic; F_dbl = zeros(1e4); toc
Elapsed time is 0.260210 seconds.
>> tic; F_log = false(1e4); toc
Elapsed time is 0.032855 seconds.
>> 0.260210 / 0.032855 % Should be close to factor 8.
ans =
7.9200
>> whos % As seen previously, factor on size is 8.
Name Size Bytes Class Attributes
F_dbl 10000x10000 800000000 double
F_log 10000x10000 100000000 logical
So the/an answer is that logicals (bytes, and not bits) are likely to be your best option (using 1GB RAM for storing 1e9 flags instead of 8GB makes a significant difference, even without thinking about access time), unless you want to cope with the overhead induced by bits manipulation for fully optimizing memory usage.