<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/287547</link>
    <title>MATLAB Central Newsreader - random vector generation within specific values</title>
    <description>Feed for thread: random vector generation within specific values</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2013 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.es/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 22 Jul 2010 20:03:26 +0000</pubDate>
      <title>random vector generation within specific values</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/287547#764839</link>
      <author>john</author>
      <description>I want to generate a random vector with the values in between -2.45 and +2.45 but no values less than +0.65 or -0.65? I would appreciate any help in this regard.&lt;br&gt;
&lt;br&gt;
Gerard</description>
    </item>
    <item>
      <pubDate>Thu, 22 Jul 2010 20:40:41 +0000</pubDate>
      <title>Re: random vector generation within specific values</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/287547#764846</link>
      <author>Walter Roberson</author>
      <description>john wrote:&lt;br&gt;
&amp;gt; I want to generate a random vector with the values in between -2.45 and +2.45 but no values less than +0.65 or -0.65? I would appreciate any help in this regard.&lt;br&gt;
&lt;br&gt;
Do you mean that you want to generate over the union of the intervals&lt;br&gt;
[-2.45, -0.65], [0.65, 2.45]&lt;br&gt;
&lt;br&gt;
??&lt;br&gt;
&lt;br&gt;
If so please be specific about whether each of the boundaries should be "open" &lt;br&gt;
or "closed".&lt;br&gt;
&lt;br&gt;
For an N x M array of random values, open intervals:&lt;br&gt;
&lt;br&gt;
(0.65 + (2.45 - 0.65) * rand(N,M)) .* (2 * (rand(N,M) &amp;gt; 0.5) - 1)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
It is possible to use only a single random number per location, but to do so &lt;br&gt;
without using a named temporary variable would require an anonymous function, &lt;br&gt;
probably needing to create an unnamed temporary matrix.</description>
    </item>
    <item>
      <pubDate>Thu, 22 Jul 2010 20:57:04 +0000</pubDate>
      <title>Re: random vector generation within specific values</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/287547#764849</link>
      <author>someone </author>
      <description>john &amp;lt;mushtaq.jaffar@yahoo.com&amp;gt; wrote in message &amp;lt;786466933.38493.1279829037211.JavaMail.root@gallium.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I want to generate a random vector with the values in between -2.45 and +2.45 but no values less than +0.65 or -0.65? I would appreciate any help in this regard.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Gerard&lt;br&gt;
&lt;br&gt;
I think you need to restate you problem.&lt;br&gt;
&lt;br&gt;
If I interpret the above literally doesn't that just mean generate random numbers between +0.65 and +2.45?&lt;br&gt;
&lt;br&gt;
% In any event:&lt;br&gt;
doc rand&lt;br&gt;
% and look at Example 5.&lt;br&gt;
&lt;br&gt;
If you are trying to generate a random number between two extremes with a "hole" in the middle, I see two ways to procede (and I'm sure there are many others).&lt;br&gt;
&lt;br&gt;
1. Generate a random number between the two extremes and throw out any number that "falls in the hole" and try again until it doesn't,  {This method may require multiple (who knows how many?) random draws per try} or&lt;br&gt;
&lt;br&gt;
2. Generate two random numbers, one in the lower extreme and one in the higher extreme.  And then randomly pick ONE of them.  {This method assures you only need two tries per draw.}</description>
    </item>
    <item>
      <pubDate>Thu, 22 Jul 2010 21:10:54 +0000</pubDate>
      <title>Re: random vector generation within specific values</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/287547#764856</link>
      <author>john</author>
      <description>kindly find here the code i want to implement:&lt;br&gt;
&lt;br&gt;
%%% CODE&lt;br&gt;
&lt;br&gt;
search_Range=[-2.45 +2.45] % here i want to mention values between -2.45 and +2.45 but no values less than +0.65 or -0.65&lt;br&gt;
&lt;br&gt;
pop_Size= 10;&lt;br&gt;
&lt;br&gt;
indiv_Size = 30;&lt;br&gt;
&lt;br&gt;
population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)-search_Range(1))*rand(pop_Size,indiv_Size);</description>
    </item>
    <item>
      <pubDate>Thu, 22 Jul 2010 21:28:56 +0000</pubDate>
      <title>Re: random vector generation within specific values</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/287547#764860</link>
      <author>Walter Roberson</author>
      <description>john wrote:&lt;br&gt;
&amp;gt; kindly find here the code i want to implement:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %%% CODE&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; search_Range=[-2.45 +2.45] % here i want to mention values between -2.45 and +2.45 but no values less than +0.65 or -0.65&lt;br&gt;
&lt;br&gt;
We are having difficulty figuring out what you mean by "but no values less &lt;br&gt;
than +0.65 or -0.65"&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;gt; pop_Size= 10;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; indiv_Size = 30;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)-search_Range(1))*rand(pop_Size,indiv_Size);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Unless the population matrix already exists and you only want to change part &lt;br&gt;
of it, you do not need the indices on the left side:&lt;br&gt;
&lt;br&gt;
population=search_Range(1)+(search_Range(2)-search_Range(1))*rand(pop_Size,indiv_Size);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
If you are trying to create a range that has a "hole" in it, and the range is &lt;br&gt;
symmetric, randomly take the negative of about half of the array (after &lt;br&gt;
setting search_range(1) to 0.65). Or just use the code I provided earlier.</description>
    </item>
    <item>
      <pubDate>Fri, 23 Jul 2010 00:33:04 +0000</pubDate>
      <title>Re: random vector generation within specific values</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/287547#764893</link>
      <author>someone </author>
      <description>john &amp;lt;mushtaq.jaffar@yahoo.com&amp;gt; wrote in message &amp;lt;1592537430.38822.1279833090745.JavaMail.root@gallium.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; kindly find here the code i want to implement:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %%% CODE&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; search_Range=[-2.45 +2.45] % here i want to mention values between -2.45 and +2.45 but no values less than +0.65 or -0.65&lt;br&gt;
&lt;br&gt;
That doesn't make much sense.&lt;br&gt;
Do you mean no values BETWEEN +0.65 and -0.65?&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; pop_Size= 10;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; indiv_Size = 30;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)-search_Range(1))*rand(pop_Size,indiv_Size);</description>
    </item>
    <item>
      <pubDate>Fri, 23 Jul 2010 01:27:03 +0000</pubDate>
      <title>Re: random vector generation within specific values</title>
      <link>http://www.mathworks.es/matlabcentral/newsreader/view_thread/287547#764898</link>
      <author>Roger Stafford</author>
      <description>john &amp;lt;mushtaq.jaffar@yahoo.com&amp;gt; wrote in message &amp;lt;1592537430.38822.1279833090745.JavaMail.root@gallium.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; kindly find here the code i want to implement:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %%% CODE&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; search_Range=[-2.45 +2.45] % here i want to mention values between -2.45 and +2.45 but no values less than +0.65 or -0.65&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; pop_Size= 10;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; indiv_Size = 30;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)-search_Range(1))*rand(pop_Size,indiv_Size);&lt;br&gt;
- - - - - - - - - - -&lt;br&gt;
&amp;nbsp;&amp;nbsp;John, you have twice said "but no values less than +0.65 or -0.65", but that seems a careless way to state things since it is surely not what you really mean nor is it even good English.  This has created needless confusion in this thread as to what you do mean.  Perhaps you mean "but no values between +0.65 and -0.65" which is the "hole in the center" interpretation others are referring to.  You should think carefully before putting out sloppy statements like the above in a newsgroup where it can be read by hundreds of others.  It makes it less likely that you will get useful help.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Assuming the hole-in-the-center interpretation is correct, you could do it this way:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;a = 2.45;&lt;br&gt;
&amp;nbsp;b = 0.65;&lt;br&gt;
&amp;nbsp;t = rand(m,n); % For m x n of them&lt;br&gt;
&amp;nbsp;r = 2*(a-b)*t-a+2*b*(t&amp;gt;=.5); % r lies either in [-a,-b] or in [b,a]&lt;br&gt;
&lt;br&gt;
(This is similar to Walter's but calls on rand only once per data point.)&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
  </channel>
</rss>
