[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to make a matrix with all combinations of digits efficiently
From: |
Jean Dubois |
Subject: |
Re: how to make a matrix with all combinations of digits efficiently |
Date: |
Fri, 29 Dec 2017 11:13:23 +0100 |
2017-12-29 0:07 GMT+01:00 Juan Pablo Carbajal <address@hidden>:
> On Thu, Dec 28, 2017 at 9:25 PM, Jean Dubois <address@hidden> wrote:
>> I'd like to generate a matrix like this (small version to give you the idea):
>>
>> 0 0 0 (three columns in this example)
>> 0 0 1
>> 0 0 2
>> 0 0 3
>> .
>> .
>> .
>> 9 9 8
>> 9 9 9
>>
>> Could anyone here show me how to do this efficiently?
>>
>> thanks in advance
>>
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://lists.gnu.org/mailman/listinfo/help-octave
>
> This is the decomposition on base 10, a way of doing it is
>
> nc = 3; # number of columns
> base = 10;
> i = (0:(base^nc-1)).'; # row index - 1
> counter = mod( floor (i ./ base.^[(nc-1):-1:0]), base);
>
> it should work for any integer base, but please do check.
Dear Juan,
I bumped into the following problem. I changed your code to a function
like this:
function [counter] = decomp (base, nc)
i = (0:(base^nc-1)).'; # row index - 1
counter = mod( floor (i ./ base.^[(nc-1):-1:0]), base);
endfunction
It works fine for a lot of cases but the case I want to use is
problematic as you can see here:
result=decomp(10,9);
error: out of memory or dimension too large for Octave's index type
error: called from
decomp at line 27 column 9
in fact I need decomp(10,10)
do you see a workaround for this problem?
kind regards,
- how to make a matrix with all combinations of digits efficiently, Jean Dubois, 2017/12/28
- Re: how to make a matrix with all combinations of digits efficiently, Juan Pablo Carbajal, 2017/12/28
- Re: how to make a matrix with all combinations of digits efficiently,
Jean Dubois <=
- Re: how to make a matrix with all combinations of digits efficiently, Juan Pablo Carbajal, 2017/12/29
- Re: how to make a matrix with all combinations of digits efficiently, Jean Dubois, 2017/12/30
- Re: how to make a matrix with all combinations of digits efficiently, Jean Dubois, 2017/12/30
- Re: how to make a matrix with all combinations of digits efficiently, Juan Pablo Carbajal, 2017/12/30
- Re: how to make a matrix with all combinations of digits efficiently, Juan Pablo Carbajal, 2017/12/30