[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: create matrix with all possible combinations.
From: |
George Barrick |
Subject: |
Re: create matrix with all possible combinations. |
Date: |
Tue, 3 Nov 2009 10:28:53 -0500 |
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 address@hidden
%%
%% 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 ) ;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: create matrix with all possible combinations.,
George Barrick <=