|
"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <iamna1$hmc$1@fred.mathworks.com>...
> "Graeme F" <graemefukuda@yahoo.com> wrote in message <iamlhp$l07$1@fred.mathworks.com>...
> > how do i get the command randint on my matlab, my version matlab 7.8 (R2009a) is too old i guess
>
> Hi,
> Do not dispair, it is rather easy to build the function randint you youselves. Here it is:
>
> function rint = randint(rows,cols,intv)
> % RANDINT Random integers
> % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> % rows number of matrix rows
> % cols number of matrix columns
> % intv vector of 2 items [low,high], boundry values of rint interval
>
> rint = round(rand(rows,cols)*(intv(2)-intv(1)) + intv(1));
>
> I think that it is without errors, nevertheless, you may repair it, if any
>
> Mira
Hi,
Yes, there was an error in the code. Improved version is as it follows:
function rint = randint(rows,cols,intv)
% RANDINT Random integers
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% rows number of matrix rows
% cols number of matrix columns
% intv vector of 2 items [low,high], boundry values of rint interval
rint = floor(rand(rows,cols)*(intv(2)+1-intv(1)) + intv(1));
Example:
hist(randint(100000,1,[-2,10]),13)
I hope that now it is good.
Mira
|