Home > utils > data2bitmask.m

data2bitmask

PURPOSE ^

data2bitmask - converts a matrix of numeric data values into bitmasks that

SYNOPSIS ^

function bitmask = data2bitmask(data, max_bit)

DESCRIPTION ^

 data2bitmask - converts a matrix of numeric data values into bitmasks that
 correspond to those values.

 maxbit - the maximum bit than can be set.  This is important insofar that it
 pads the mask with extra columns in the event that none of the data values
 set the highest bit

 bitmask is a logical vector

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function bitmask = data2bitmask(data, max_bit)
0002 % data2bitmask - converts a matrix of numeric data values into bitmasks that
0003 % correspond to those values.
0004 %
0005 % maxbit - the maximum bit than can be set.  This is important insofar that it
0006 % pads the mask with extra columns in the event that none of the data values
0007 % set the highest bit
0008 %
0009 % bitmask is a logical vector
0010 
0011 % 09/09/05 Petr Janata
0012 
0013 % convert the number to a binary representation as a string of zeros and ones
0014 bin = dec2bin(data);
0015 
0016 % convert the ascii characters to their numeric values and subtract the numeric
0017 % value for '0'
0018 bitmask  = double(bin)-double('0');
0019 
0020 % since the most significant bit is currently on the left, we want to flip the
0021 % matrix left to right so that the column number corresponds to the bit number
0022 bitmask = fliplr(bitmask);
0023 
0024 % if a maximum bit has been specified, make sure that the number of columns in
0025 % our mask corresponds to the desired number of bits
0026 if exist('max_bit','var') && max_bit > size(bitmask,2)
0027   bitmask(end,max_bit) = 0;
0028 end
0029 
0030 bitmask = logical(bitmask);
0031 
0032 return

Generated on Wed 22-May-2019 04:00:51 by m2html © 2003