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:
vector of random unifromly spaced numbers on a given interval

Subject: vector of random unifromly spaced numbers on a given interval

From: Chelsea

Date: 18 Jan, 2012 19:12:10

Message: 1 of 6

Hello, I have to create a vector of given length that is made up of randomly generated, uniformly spaced numbers from 2 to 9. How would I go about doing this? I can only use one line to do so :/ Please help

Thank you!

Subject: vector of random unifromly spaced numbers on a given interval

From: James Tursa

Date: 18 Jan, 2012 19:24:11

Message: 2 of 6

"Chelsea " <brass4all@gmail.com> wrote in message <jf75ia$oc4$1@newscl01ah.mathworks.com>...
> Hello, I have to create a vector of given length that is made up of randomly generated, uniformly spaced numbers from 2 to 9. How would I go about doing this? I can only use one line to do so :/ Please help
>
> Thank you!

I just placed your title into Google, "vector of random unifromly spaced numbers on a given interval", and the very first link shown is this:

http://msenux.redwoods.edu/Math4Textbook/VectorsAndMatrices/Vectors.pdf

and it has the following example in it:

"Generate a vector that contains 1000 uniform random numbers
on the interval [0, 10]"

Seems like you could easily adapt that example for your purposes. (Also seems like you could have Googled this yourself)

James Tursa

Subject: vector of random unifromly spaced numbers on a given interval

From: Roger Stafford

Date: 18 Jan, 2012 19:54:10

Message: 3 of 6

"Chelsea " <brass4all@gmail.com> wrote in message <jf75ia$oc4$1@newscl01ah.mathworks.com>...
> Hello, I have to create a vector of given length that is made up of randomly generated, uniformly spaced numbers from 2 to 9. How would I go about doing this? I can only use one line to do so :/ Please help
>
> Thank you!
- - - - - - - -
  Strictly speaking the terms "randomly generated" and "uniformly spaced" are mutually incompatible. Perhaps you mean possessing a statistically uniform distribution on the interval [2,9]. If so do this:

 v = (9-2)*rand(n,1)+2;

where n is the desired length.

  If you mean anything else, you need to describe it more accurately than you have.

Roger Stafford

Subject: vector of random unifromly spaced numbers on a given interval

From: Bryan

Date: 18 Jan, 2012 22:50:10

Message: 4 of 6

"Roger Stafford" wrote in message <jf7812$3ea$1@newscl01ah.mathworks.com>...
> "Chelsea " <brass4all@gmail.com> wrote in message <jf75ia$oc4$1@newscl01ah.mathworks.com>...
> > Hello, I have to create a vector of given length that is made up of randomly generated, uniformly spaced numbers from 2 to 9. How would I go about doing this? I can only use one line to do so :/ Please help
> >
> > Thank you!
> - - - - - - - -
> Strictly speaking the terms "randomly generated" and "uniformly spaced" are mutually incompatible. Perhaps you mean possessing a statistically uniform distribution on the interval [2,9]. If so do this:
>
> v = (9-2)*rand(n,1)+2;
>
> where n is the desired length.
>
> If you mean anything else, you need to describe it more accurately than you have.
>
> Roger Stafford

Roger, She actually put it virtually ver batim, it just needs to be transposed in addition to what she already stated. It is an "essentials" question from our 2nd homework assignment. Use of rand will solve the problem.

Chelsea, try using the Piazza set up for the course, it will yield better results to hw inquiries, and quicker. Use the help command in your matlab command window to see how to properly use the rand function. It should help you get the correct answer quickly.

Bryan

Subject: vector of random unifromly spaced numbers on a given interval

From: James Tursa

Date: 18 Jan, 2012 23:38:10

Message: 5 of 6

"Bryan" wrote in message <jf7ib2$90v$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jf7812$3ea$1@newscl01ah.mathworks.com>...
> > - - - - - - - -
> > Strictly speaking the terms "randomly generated" and "uniformly spaced" are mutually incompatible. Perhaps you mean possessing a statistically uniform distribution on the interval [2,9].
> >
> > Roger Stafford
>
> Roger, She actually put it virtually ver batim, it just needs to be transposed in addition to what she already stated. It is an "essentials" question from our 2nd homework assignment. Use of rand will solve the problem.

Bryan, maybe you could have a talk with the question writer and point out the incorrect wording of the problem. It seems "uniformly distributed" was meant, not "uniformly spaced". An instructor should use correct terminology (well ... we all should for that matter :) ).

James Tursa

Subject: vector of random unifromly spaced numbers on a given interval

From: g.heath@verizon.net

Date: 20 Jan, 2012 05:40:56

Message: 6 of 6

On Jan 18, 6:38 pm, "James Tursa"
<aclassyguy_with_a_k_not_...@hotmail.com> wrote:
> "Bryan" wrote in message <jf7ib2$90...@newscl01ah.mathworks.com>...
> > "Roger Stafford" wrote in message <jf7812$3e...@newscl01ah.mathworks.com>...
> > > - - - - - - - -
> > >   Strictly speaking the terms "randomly generated" and "uniformly spaced" are mutually incompatible.  Perhaps you mean possessing a statistically uniform distribution on the interval [2,9].
>
> > > Roger Stafford
>
> > Roger, She actually put it virtually ver batim, it just needs to be transposed in addition to what she already stated.  It is an "essentials" question from our 2nd homework assignment.  Use of rand will solve the problem.
>
> Bryan, maybe you could have a talk with the question writer and point out the incorrect wording of the problem. It seems "uniformly distributed" was meant, not "uniformly spaced". An instructor should use correct terminology (well ... we all should for that matter :) ).
>
> James Tursa

Yes. I interpreted the statement as looking for

1+randperm(8)

Hope this helps.

Greg

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