help-octave
[Top][All Lists]
Advanced

[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: Juan Pablo Carbajal
Subject: Re: how to make a matrix with all combinations of digits efficiently
Date: Sat, 30 Dec 2017 18:42:05 +0100

> I just saw that dec2digit(100) produces 0 0 in stead of 1 0 0, so I
> changed the function as follows
> function digits = dec2digit (num, nc, base = 10)
> %nc      = ceil (log (num) / log (base));
> digits=mod(floor(num./base.^[(nc-1):-1:0]), base);

a better fix is probably to force rounding up.

function digits = dec2digit (num, base = 10)
nc      = floor (log (num) / log (base)) + 1;
digits = mod(floor(num./base.^[(nc-1):-1:0]), base);
endfunction



reply via email to

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