Thread Subject: 5 Elements Randomly Distributed in Matrix

Subject: 5 Elements Randomly Distributed in Matrix

From: Tim Smith

Date: 19 Nov, 2008 19:17:05

Message: 1 of 3

Hey everyone i hope you can help me with this problem:

I need to create a matrix where:

A% of the elements = 0
B% of the elements = 1
C% of the elements = 2
D% of the elements = 3
E% of the elements = 4

A+B+C+D+E=100%

and these values are randomly distributed throughout the matrix.

Subject: 5 Elements Randomly Distributed in Matrix

From: dpb

Date: 19 Nov, 2008 19:31:28

Message: 2 of 3

Tim Smith wrote:
> Hey everyone i hope you can help me with this problem:
>
> I need to create a matrix where:
>
> A% of the elements = 0
> B% of the elements = 1
> C% of the elements = 2
> D% of the elements = 3
> E% of the elements = 4
>
> A+B+C+D+E=100%
>
> and these values are randomly distributed throughout the matrix.

If the percentages aren't random, the number of elements of each value
is fixed based on the size of the array. Simply generate a random
permutation of the array indices in 1:M*N and reshape.

--

Subject: 5 Elements Randomly Distributed in Matrix

From: Adam

Date: 19 Nov, 2008 19:47:01

Message: 3 of 3

Tim Smith <imaccormick@gmail.com> wrote in message <30353534.1227122262474.JavaMail.jakarta@nitrogen.mathforum.org>...
> Hey everyone i hope you can help me with this problem:
>
> I need to create a matrix where:
>
> A% of the elements = 0
> B% of the elements = 1
> C% of the elements = 2
> D% of the elements = 3
> E% of the elements = 4
>
> A+B+C+D+E=100%
>
> and these values are randomly distributed throughout the matrix.

val = [40 30 20 5 5];
yo = [repmat(0, [1 val(1)]), repmat(1, [1 val(2)]), repmat(2, [1 val(3)]), repmat(3, [1 val(4)]), repmat(4, [1 val(5)])];

yo = reshape(yo(randperm(100)), [10 10]);

~Adam

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com