From: john on
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.

Gerard
From: Walter Roberson on
john wrote:
> 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.

Do you mean that you want to generate over the union of the intervals
[-2.45, -0.65], [0.65, 2.45]

??

If so please be specific about whether each of the boundaries should be "open"
or "closed".

For an N x M array of random values, open intervals:

(0.65 + (2.45 - 0.65) * rand(N,M)) .* (2 * (rand(N,M) > 0.5) - 1)


It is possible to use only a single random number per location, but to do so
without using a named temporary variable would require an anonymous function,
probably needing to create an unnamed temporary matrix.
From: someone on
john <mushtaq.jaffar(a)yahoo.com> wrote in message <786466933.38493.1279829037211.JavaMail.root(a)gallium.mathforum.org>...
> 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.
>
> Gerard

I think you need to restate you problem.

If I interpret the above literally doesn't that just mean generate random numbers between +0.65 and +2.45?

% In any event:
doc rand
% and look at Example 5.

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).

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

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.}
From: john on
kindly find here the code i want to implement:

%%% CODE

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

pop_Size= 10;

indiv_Size = 30;

population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)-search_Range(1))*rand(pop_Size,indiv_Size);
From: Walter Roberson on
john wrote:
> kindly find here the code i want to implement:
>
> %%% CODE
>
> 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

We are having difficulty figuring out what you mean by "but no values less
than +0.65 or -0.65"


> pop_Size= 10;
>
> indiv_Size = 30;
>
> population(1:pop_Size,1:indiv_Size)=search_Range(1)+(search_Range(2)-search_Range(1))*rand(pop_Size,indiv_Size);


Unless the population matrix already exists and you only want to change part
of it, you do not need the indices on the left side:

population=search_Range(1)+(search_Range(2)-search_Range(1))*rand(pop_Size,indiv_Size);


If you are trying to create a range that has a "hole" in it, and the range is
symmetric, randomly take the negative of about half of the array (after
setting search_range(1) to 0.65). Or just use the code I provided earlier.