Re: create matrix with all possible combinations.

View: New views
1 Messages — Rating Filter:   Alert me  

Re: create matrix with all possible combinations.

by George Barrick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


                         2009.11.03.15:24:56 UT

Hello xeon,

    You can create your array of zeros and ones
using a vectorized call to the octave bitget()
function.  I've pasted a bit of code with comments
below this paragraph.  It is only six lines
of code; but I like to extensively comment my
octave scripts so that I can read through my
thinking months (or more) later.

    I hope you like my code.

George                    gbarrick@...


%%
%%    Start with a column consisting of the first
%% 256 integers.
%%
%%    Set bigN to be the length of the list.
%%
%%    Inflate that list to a 256x8 array where
%% the same integer is repeated eight times across
%% each row.
%%

numlist = [ 0 : 255 ]'                ;
bigN    =  max( size( numlist ) )     ;
intmtrx =  numlist * ones( 1, 8 )     ;

%%
%%    List the bit positions in descending order
%% in the 1x8 array idx.
%%
%%    Inflate the list of positions into a 256x8
%% array where the same position is repeated 256
%% times down each column.
%%

idx     =   8 : -1 : 1                ;
indexes =  ones( bigN, 1 ) * idx      ;

%%
%%    Make a vectorized call to the bitget()
%% function.  It outputs a 256x8 array in which
%% each integer from the first array is queried
%% for a particular bit of its binary
%% representation.
%%

bitmtrx =  bitget( intmtrx, indexes ) ;



_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave