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:
Generate non integer number

Subject: Generate non integer number

From: max200790

Date: 13 Mar, 2013 14:05:09

Message: 1 of 5

Hi,
 I would know how I can generate a non integer number with the function randi without utilizing a division or multiplication.

Maybe we know another function which only specifying the interval give the random value as:

Amin=0
Amax=5
A=......([Amin,Amax])


A=1.954

Thanks

 

Subject: Generate non integer number

From: someone

Date: 13 Mar, 2013 14:35:08

Message: 2 of 5

"max200790" wrote in message <khq12l$1kc$1@newscl01ah.mathworks.com>...
> Hi,
> I would know how I can generate a non integer number with the function randi without utilizing a division or multiplication.
>
> Maybe we know another function which only specifying the interval give the random value as:
>
> Amin=0
> Amax=5
> A=......([Amin,Amax])
>
>
> A=1.954
>

This may skirt the issue, but you could use something like SQRT, EXP, some trig function, or any combination of them perhaps.
> Thanks
>
>

Subject: Generate non integer number

From: Alan_Weiss

Date: 13 Mar, 2013 15:10:08

Message: 3 of 5

On 3/13/2013 10:05 AM, max200790 wrote:
> Hi,
> I would know how I can generate a non integer number with the
> function randi without utilizing a division or multiplication.
> Maybe we know another function which only specifying the interval give
> the random value as:
>
> Amin=0
> Amax=5
> A=......([Amin,Amax])
>
>
> A=1.954
>
> Thanks
>

A = Amin + (Amax - Amin)*rand

If Amin and Amax are vectors or matrices,

A = Amin + rand(size(Amin)).*(Amax - Amin)

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: Generate non integer number

From: someone

Date: 13 Mar, 2013 15:52:07

Message: 4 of 5

Alan_Weiss <aweiss@mathworks.com> wrote in message <khq4sg$e5a$1@newscl01ah.mathworks.com>...
> On 3/13/2013 10:05 AM, max200790 wrote:
> > Hi,
> > I would know how I can generate a non integer number with the
> > function randi without utilizing a division or multiplication.
> > Maybe we know another function which only specifying the interval give
> > the random value as:
> >
> > Amin=0
> > Amax=5
> > A=......([Amin,Amax])
> >
> >
> > A=1.954
> >
> > Thanks
> >
>
> A = Amin + (Amax - Amin)*rand
>
> If Amin and Amax are vectors or matrices,
>
> A = Amin + rand(size(Amin)).*(Amax - Amin)
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

The above uses the function rand - NOT randi.

Subject: Generate non integer number

From: John D'Errico

Date: 13 Mar, 2013 17:39:08

Message: 5 of 5

"max200790" wrote in message <khq12l$1kc$1@newscl01ah.mathworks.com>...
> Hi,
> I would know how I can generate a non integer number with the function randi without utilizing a division or multiplication.
>
> Maybe we know another function which only specifying the interval give the random value as:
>
> Amin=0
> Amax=5
> A=......([Amin,Amax])
>
>
> A=1.954
>

Well, without telling us WHY you want to do this
(yes, I know its homework) or what distribution
of numbers you need, how can we really help you?

A = randi(1) + 0.5;

A will always be non-integer. Clearly it satisfies your
requirements as stated, but I fear it does not do
what you need. But how do we know what you
really need?

John

Tags for this Thread

No tags are associated with 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