Home > reduc > bitsearch.m

bitsearch

PURPOSE ^

function ind=bitsearch(v,bit,logical)

SYNOPSIS ^

function ind=bitsearch(v,bit,logical)

DESCRIPTION ^

 function ind=bitsearch(v,bit,logical)

 v - Nx1 or 1xN vector
 bit - bits to search for.  For multiple bits, input as array
 logical - 'only' -> for elements of v that only contains bit value, bits
         - 'all' or 'any' -> for elements of v that contains any of the bit
           values in bits
 
 ind=bitsearch(d.array.frame.features,[1 2], 'all')
  
 this extracts all features containing both bits f1 and f2 regardless of
 what other features bits are set.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ind=bitsearch(v,bit,logical)
0002 
0003 % function ind=bitsearch(v,bit,logical)
0004 %
0005 % v - Nx1 or 1xN vector
0006 % bit - bits to search for.  For multiple bits, input as array
0007 % logical - 'only' -> for elements of v that only contains bit value, bits
0008 %         - 'all' or 'any' -> for elements of v that contains any of the bit
0009 %           values in bits
0010 %
0011 % ind=bitsearch(d.array.frame.features,[1 2], 'all')
0012 %
0013 % this extracts all features containing both bits f1 and f2 regardless of
0014 % what other features bits are set.
0015 %
0016 
0017 % v must be Nx1 or 1xN vector
0018 if (ndims(v)>2)
0019   error('Argument ''v'' must be a Nx1 or 1xN vector')
0020 else
0021   [a,b]=size(v);
0022   if (a~=1 & b~=1)
0023     error('Argument''v'' must be a Nx1 or 1xN vector')
0024   end
0025 end
0026 
0027 mask=0;
0028 for i=1:length(bit)
0029   mask=mask+2^bit(i);
0030 end
0031 
0032 switch logical
0033   case 'only'
0034     ind=v==mask;
0035     
0036   case {'all','any'}
0037     ind=bitand(uint32(v),uint32(mask));
0038     ind=ind==mask;
0039     
0040   otherwise
0041     error('Invalid ''logical'' argument')
0042 end

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005