<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239531</link>
    <title>MATLAB Central Newsreader - 5 Elements Randomly Distributed in Matrix</title>
    <description>Feed for thread: 5 Elements Randomly Distributed in Matrix</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 19 Nov 2008 19:17:05 -0500</pubDate>
      <title>5 Elements Randomly Distributed in Matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239531#611888</link>
      <author>Tim Smith</author>
      <description>Hey everyone i hope you can help me with this problem:&lt;br&gt;
&lt;br&gt;
I need to create a matrix where:&lt;br&gt;
&lt;br&gt;
A% of the elements = 0&lt;br&gt;
B% of the elements = 1&lt;br&gt;
C% of the elements = 2&lt;br&gt;
D% of the elements = 3&lt;br&gt;
E% of the elements = 4&lt;br&gt;
&lt;br&gt;
A+B+C+D+E=100%&lt;br&gt;
&lt;br&gt;
and these values are randomly distributed throughout the matrix.</description>
    </item>
    <item>
      <pubDate>Wed, 19 Nov 2008 19:31:28 -0500</pubDate>
      <title>Re: 5 Elements Randomly Distributed in Matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239531#611893</link>
      <author>dpb</author>
      <description>Tim Smith wrote:&lt;br&gt;
&amp;gt; Hey everyone i hope you can help me with this problem:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I need to create a matrix where:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A% of the elements = 0&lt;br&gt;
&amp;gt; B% of the elements = 1&lt;br&gt;
&amp;gt; C% of the elements = 2&lt;br&gt;
&amp;gt; D% of the elements = 3&lt;br&gt;
&amp;gt; E% of the elements = 4&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A+B+C+D+E=100%&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; and these values are randomly distributed throughout the matrix.&lt;br&gt;
&lt;br&gt;
If the percentages aren't random, the number of elements of each value &lt;br&gt;
is fixed based on the size of the array.  Simply generate a random &lt;br&gt;
permutation of the array indices in 1:M*N and reshape.&lt;br&gt;
&lt;br&gt;
--</description>
    </item>
    <item>
      <pubDate>Wed, 19 Nov 2008 19:47:01 -0500</pubDate>
      <title>Re: 5 Elements Randomly Distributed in Matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239531#611898</link>
      <author>Adam </author>
      <description>Tim Smith &amp;lt;imaccormick@gmail.com&amp;gt; wrote in message &amp;lt;30353534.1227122262474.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Hey everyone i hope you can help me with this problem:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I need to create a matrix where:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A% of the elements = 0&lt;br&gt;
&amp;gt; B% of the elements = 1&lt;br&gt;
&amp;gt; C% of the elements = 2&lt;br&gt;
&amp;gt; D% of the elements = 3&lt;br&gt;
&amp;gt; E% of the elements = 4&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A+B+C+D+E=100%&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; and these values are randomly distributed throughout the matrix.&lt;br&gt;
&lt;br&gt;
val = [40 30 20 5 5];&lt;br&gt;
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)])];&lt;br&gt;
&lt;br&gt;
yo = reshape(yo(randperm(100)), [10 10]);&lt;br&gt;
&lt;br&gt;
~Adam</description>
    </item>
  </channel>
</rss>

