function y = concat(I) %concat: concatenate bitstrings %I is a vector of indices for two or more bitstrings %Usage: % I = [ 3 5 1 2 ] % y = concat(I)' % print_without_spaces(y) % fprintf(1,'\n') %creates in memory the bitstring %y consisting of the left to right concatenation of the %bitstrings from I, % y = [ 0 0 1 0 0 1 ] % and prints this string to the screen % 001001 % . % documented in % ftp://oz.ee.umn.edu/users/kieffer/seminar/notes2.ps % Change log: % 1999-06-30:DAV: This was very slow for large images, so I sped it up. % Now it's much faster. % 1999-05-06:DAV: more documentation by David Cary % ???:JCK: originally by John C. Kieffer % http://www.ee.umn.edu/users/kieffer/programs.html [bitlength, value] = index_to_binary(I(:)); maxbits = max(bitlength(:)); % value = uint32(value); activates strange bug in bitget() in MATLAB Version 5.1.0.421 on PCWIN % build the results, one codeword per column, % one row per bit. list = zeros( maxbits, length(I) ); % mostly from index_to_bitstring by Kieffer current_bit = 1; z = zeros( length(I), 1 ); % reserve space for i=maxbits:-1:1, % find which columns have valid bits. valid_bits = current_bit <= bitlength; % get next row of bits. z(:) = bitget(value,current_bit)+valid_bits; % profile says this is slow (5 s !) % For each cell of z, % 0 == invalid "empty". % 1 == valid "0" bit % 2 == valid "1" bit. list( i, : ) = z'; % insert into matrix current_bit = current_bit+1; end; % Strip out "empty" places (currently filled with "0"). [dummyrow, dummycolumn, y] = find( list ); y = logical(y - 1); if(0) % working original program. Probably faster in C. % 38 s on DAV's machine. N=length(I); y=[]; for i=1:N; A=index_to_bitstring(I(i)); y=[y A]; end end;