http://www.mathworks.com/matlabcentral/newsreader/view_thread/287547
MATLAB Central Newsreader  random vector generation within specific values
Feed for thread: random vector generation within specific values
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Thu, 22 Jul 2010 20:03:26 +0000
random vector generation within specific values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287547#764839
john
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.<br>
<br>
Gerard

Thu, 22 Jul 2010 20:40:41 +0000
Re: random vector generation within specific values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287547#764846
Walter Roberson
john wrote:<br>
> 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.<br>
<br>
Do you mean that you want to generate over the union of the intervals<br>
[2.45, 0.65], [0.65, 2.45]<br>
<br>
??<br>
<br>
If so please be specific about whether each of the boundaries should be "open" <br>
or "closed".<br>
<br>
For an N x M array of random values, open intervals:<br>
<br>
(0.65 + (2.45  0.65) * rand(N,M)) .* (2 * (rand(N,M) > 0.5)  1)<br>
<br>
<br>
It is possible to use only a single random number per location, but to do so <br>
without using a named temporary variable would require an anonymous function, <br>
probably needing to create an unnamed temporary matrix.

Thu, 22 Jul 2010 20:57:04 +0000
Re: random vector generation within specific values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287547#764849
someone
john <mushtaq.jaffar@yahoo.com> wrote in message <786466933.38493.1279829037211.JavaMail.root@gallium.mathforum.org>...<br>
> 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.<br>
> <br>
> Gerard<br>
<br>
I think you need to restate you problem.<br>
<br>
If I interpret the above literally doesn't that just mean generate random numbers between +0.65 and +2.45?<br>
<br>
% In any event:<br>
doc rand<br>
% and look at Example 5.<br>
<br>
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).<br>
<br>
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<br>
<br>
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.}

Thu, 22 Jul 2010 21:10:54 +0000
Re: random vector generation within specific values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287547#764856
john
kindly find here the code i want to implement:<br>
<br>
%%% CODE<br>
<br>
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<br>
<br>
pop_Size= 10;<br>
<br>
indiv_Size = 30;<br>
<br>
population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)search_Range(1))*rand(pop_Size,indiv_Size);

Thu, 22 Jul 2010 21:28:56 +0000
Re: random vector generation within specific values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287547#764860
Walter Roberson
john wrote:<br>
> kindly find here the code i want to implement:<br>
> <br>
> %%% CODE<br>
> <br>
> 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<br>
<br>
We are having difficulty figuring out what you mean by "but no values less <br>
than +0.65 or 0.65"<br>
<br>
<br>
> pop_Size= 10;<br>
> <br>
> indiv_Size = 30;<br>
> <br>
> population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)search_Range(1))*rand(pop_Size,indiv_Size);<br>
<br>
<br>
Unless the population matrix already exists and you only want to change part <br>
of it, you do not need the indices on the left side:<br>
<br>
population=search_Range(1)+(search_Range(2)search_Range(1))*rand(pop_Size,indiv_Size);<br>
<br>
<br>
If you are trying to create a range that has a "hole" in it, and the range is <br>
symmetric, randomly take the negative of about half of the array (after <br>
setting search_range(1) to 0.65). Or just use the code I provided earlier.

Fri, 23 Jul 2010 00:33:04 +0000
Re: random vector generation within specific values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287547#764893
someone
john <mushtaq.jaffar@yahoo.com> wrote in message <1592537430.38822.1279833090745.JavaMail.root@gallium.mathforum.org>...<br>
> kindly find here the code i want to implement:<br>
> <br>
> %%% CODE<br>
> <br>
> 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<br>
<br>
That doesn't make much sense.<br>
Do you mean no values BETWEEN +0.65 and 0.65?<br>
<br>
> <br>
> pop_Size= 10;<br>
> <br>
> indiv_Size = 30;<br>
> <br>
> population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)search_Range(1))*rand(pop_Size,indiv_Size);

Fri, 23 Jul 2010 01:27:03 +0000
Re: random vector generation within specific values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287547#764898
Roger Stafford
john <mushtaq.jaffar@yahoo.com> wrote in message <1592537430.38822.1279833090745.JavaMail.root@gallium.mathforum.org>...<br>
> kindly find here the code i want to implement:<br>
> <br>
> %%% CODE<br>
> <br>
> 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<br>
> <br>
> pop_Size= 10;<br>
> <br>
> indiv_Size = 30;<br>
> <br>
> population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)search_Range(1))*rand(pop_Size,indiv_Size);<br>
          <br>
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.<br>
<br>
Assuming the holeinthecenter interpretation is correct, you could do it this way:<br>
<br>
a = 2.45;<br>
b = 0.65;<br>
t = rand(m,n); % For m x n of them<br>
r = 2*(ab)*ta+2*b*(t>=.5); % r lies either in [a,b] or in [b,a]<br>
<br>
(This is similar to Walter's but calls on rand only once per data point.)<br>
<br>
Roger Stafford