help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [newbie] constructing a discrete dataset


From: c.
Subject: Re: [newbie] constructing a discrete dataset
Date: Wed, 29 Jan 2014 17:25:17 +0100

On 29 Jan 2014, at 17:07, Jean Dubois <address@hidden> wrote:

> I'd like to generate every possible combination a b c d e f for three
> possible values (1, 2, 3) of each variable
> Something which starts like this:
> 1 1 1 1 1 1
> 1 1 1 1 1 2
> 1 1 1 1 1 3
> 1 1 1 1 2 1
> 1 1 1 1 2 2
> 1 1 1 1 2 3
> 1 1 1 1 3 1
> 1 1 1 1 3 2
> 1 1 1 1 3 3
> 1 1 1 2 1 1
> 1 1 1 2 1 2
> 1 1 1 2 1 3
> 1 1 1 2 2 1
> 1 1 1 2 2 2
> 1 1 1 2 2 3
> 1 1 1 2 3 1
> 1 1 1 2 3 2
> 1 1 1 2 3 3
> .
> .
> .
> Can anyone here suggest how this is best done in octave in a time
> efficient manner (I suppose nested for-loops are a bad idea)?

If I understand correctly what you want to do is count fro 0 to 3^7-1 in base 3:

ii = [0:3^7-1].';
for jj = 1:7
 digit(:, jj) = fix (ii / 3^(7-jj));
 ii -= digit(:, jj) * 3^(7-jj);
endfor
digit += 1;

does this do what you want?

> thanks in advance
> jean

HTH,
c.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]