Got Questions? Get Answers.
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 long random vector by repeating 12 means and stds

Subject: generate long random vector by repeating 12 means and stds

From: Kirk

Date: 15 Jan, 2009 15:37:02

Message: 1 of 3

I need to generate 1200 random elements from 12 mean values and 12 standard deviations.

I have created the vectors:
y_mu = [-7.22,-3.67,2.40,11.25,19.11,23.89,26.73,25.26,19.61,12.78,2.38,-4.82]
y_sigma = [3.04,2.82,2.48,2.73,2.26,1.78,1.64,1.77,1.79,2.06,2.46,2.63]

I then used normrnd to generate a new vector of 12 random elments:
y_rand = normrnd(y_mu,y_sigma,1,12);

My trouble is that I need to do this 100 times, generating a vector with a dimension of 1,1200 every 12 elements represent a new call to the function normrand generating 12 new random elements based on the 12 y_mu and y_sigma.

Should this be done in a loop? or is there a more elegant Matlab-ish approach?

Subject: generate long random vector by repeating 12 means and stds

From: Roger Stafford

Date: 15 Jan, 2009 16:11:02

Message: 2 of 3

"Kirk" <kwythers.nospam@umn.edu> wrote in message <gknl6u$p5t$1@fred.mathworks.com>...
> I need to generate 1200 random elements from 12 mean values and 12 standard deviations.
>
> I have created the vectors:
> y_mu = [-7.22,-3.67,2.40,11.25,19.11,23.89,26.73,25.26,19.61,12.78,2.38,-4.82]
> y_sigma = [3.04,2.82,2.48,2.73,2.26,1.78,1.64,1.77,1.79,2.06,2.46,2.63]
>
> I then used normrnd to generate a new vector of 12 random elments:
> y_rand = normrnd(y_mu,y_sigma,1,12);
>
> My trouble is that I need to do this 100 times, generating a vector with a dimension of 1,1200 every 12 elements represent a new call to the function normrand generating 12 new random elements based on the 12 y_mu and y_sigma.
>
> Should this be done in a loop? or is there a more elegant Matlab-ish approach?
>
  You can do it with one call to 'normrnd' if you do a 'repmat' on 'y_mu' and 'y_sigma'.

 y_rand = normrnd(repmat(y_mu,1,100),repmat(y_sigma,1,100));

  Note: This advice is based on reading the documentation. I haven't actually used 'normrnd' myself.

Roger Stafford

Subject: generate long random vector by repeating 12 means and stds

From: Kirk

Date: 15 Jan, 2009 16:34:04

Message: 3 of 3

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message
> >
> > Should this be done in a loop? or is there a more elegant Matlab-ish approach?
> >
> You can do it with one call to 'normrnd' if you do a 'repmat' on 'y_mu' and 'y_sigma'.
>
> y_rand = normrnd(repmat(y_mu,1,100),repmat(y_sigma,1,100));
>
> Note: This advice is based on reading the documentation. I haven't actually used 'normrnd' myself.
>
> Roger Stafford

That's a nice solution. Thank you.

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