Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
RANDINT

Subject: RANDINT

From: Graeme F

Date: 1 Nov, 2010 15:15:05

Message: 1 of 5

how do i get the command randint on my matlab, my version matlab 7.8 (R2009a) is too old i guess

Subject: RANDINT

From: Sean

Date: 1 Nov, 2010 15:24:04

Message: 2 of 5

> how do i get the command randint on my matlab, my version matlab 7.8 (R2009a) is too old i guess

By reading Steven Lord's response in your other thread.

Subject: RANDINT

From: Wayne King

Date: 1 Nov, 2010 15:29:05

Message: 3 of 5

"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

randint() is part of the Communications Toolbox. If you do not have this in your installation, I assume that you do not have that toolbox.

By the way, that function is in the process of being obsoleted and you are recommended to use randi() instead which is part of base MATLAB.

Wayne

Subject: RANDINT

From: Miroslav Balda

Date: 1 Nov, 2010 15:45:06

Message: 4 of 5

"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

Subject: RANDINT

From: Miroslav Balda

Date: 1 Nov, 2010 16:29:04

Message: 5 of 5

"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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us