Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!newsfeed00.sul.t-online.de!t-online.de!news.k-dsl.de!aioe.org!not-for-mail
From: dpb <none@non.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 5 Elements Randomly Distributed in Matrix
Date: Wed, 19 Nov 2008 13:31:28 -0600
Organization: Aioe.org NNTP Server
Lines: 20
Message-ID: <gg1pqg$fvt$2@aioe.org>
References: <30353534.1227122262474.JavaMail.jakarta@nitrogen.mathforum.org>
NNTP-Posting-Host: lWUsD+NakTVTCSJXyDkNrA.user.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
NNTP-Posting-Date: Wed, 19 Nov 2008 19:35:45 +0000 (UTC)
X-Notice: Filtered by postfilter v. 0.7.4
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
Xref: news.mathworks.com comp.soft-sys.matlab:501817


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.

--