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 20:22:05 +0100

Please use "reply all" instead of "reply" to keep the list in CC.

On 29 Jan 2014, at 19:38, Jean Dubois <address@hidden> wrote:

> 2014-01-29 c. <address@hidden>:
>>> 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
>> 
>> On 29 Jan 2014, at 17:25, c. <address@hidden> wrote:
>> 
>>> If I understand correctly what you want to do is count fro 0 to 3^7-1 in 
>>> base 3:
>> oops, you actually wanted 6 digits, not 7, so that's 3^6-1, not 3^7-1:
>> 
>> ii = [0:3^6-1].';
>> for jj = 1:6
>>  digit(:, jj) = fix (ii / 3^(6-jj));
>>  ii -= digit(:, jj) * 3^(6-jj);
>> endfor
>> digit += 1;
>> 

> Thanks a lot, this does indeed what I asked. I have to admit I don't
> yet understand your code. Could you just  you explain what the code -=
> does? (help -= doesn't give me an answer)

you are right, there is no 'help' for '-=' but there is an enty in the manual, 
try

doc -=

anyway, 

a -= b

is nothing else but a shortcut for 

a = a - b

> I also tried to make it work for other bases and number of digits like this:
> base=input('base? ')
> nod=input('number of digits? ')
> ii = [0:base^nod-1].';
> for jj = 1:nod
>  digit(:, jj) = fix (ii / base^(nod-jj));
>  ii -= digit(:, jj) * base^(nod-jj);
> endfor
> digit += 1;
> 
> It breaks however for some values e.g. base 11 and 12 digits


that's not surprising as in that case you are asking to create a matrix with 

11^12 = 3.1384e+12

entries, which is more that Octave can index
unless you compiled with 64bit indexing enabled:

>> intmax 
ans = 2147483647

do you really need to create a table that large?

> thanks in advance
> jean

c.

reply via email to

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