Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 5 Elements Randomly Distributed in Matrix
Date: Wed, 19 Nov 2008 19:47:01 +0000 (UTC)
Organization: Atlantic Inertial Systems
Lines: 21
Message-ID: <gg1qfl$4v6$1@fred.mathworks.com>
References: <30353534.1227122262474.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227124021 5094 172.30.248.37 (19 Nov 2008 19:47:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 19 Nov 2008 19:47:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1405925
Xref: news.mathworks.com comp.soft-sys.matlab:501822


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