Generation of random number which needs to be passed to an array

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Generation of random number which needs to be passed to an array

GK19
I have 2 variables named A and B

A  has the range from -0.2 to 2.2 
B has the range from  -3.2 to 0.2

I need all the possible to combinations of A and B in 0.1 steps

for example 

A                        B
0.1                  0.2
-0.1               -0.3 and so on 

How do I randomly generate this?


Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

Doug Stewart-4


On Mon, Jun 15, 2020 at 4:33 PM Ganesh Kini <[hidden email]> wrote:
I have 2 variables named A and B

A  has the range from -0.2 to 2.2 
B has the range from  -3.2 to 0.2

I need all the possible to combinations of A and B in 0.1 steps

for example 

A                        B
0.1                  0.2
-0.1               -0.3 and so on 

How do I randomly generate this?

I am not sure what you want, but this might help.

a=-.2:.1:2.2;
b=-3.2:.1:.2;
r1=randi(numel(a))
r2=randi(numel(b))
c=[a(r1) , b(r2)]

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

GK19
Thank you

I can i iterate all the values without using for loop,

SInce there are many combinations I want to avoid for loop

On Mon, Jun 15, 2020 at 10:44 PM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 4:33 PM Ganesh Kini <[hidden email]> wrote:
I have 2 variables named A and B

A  has the range from -0.2 to 2.2 
B has the range from  -3.2 to 0.2

I need all the possible to combinations of A and B in 0.1 steps

for example 

A                        B
0.1                  0.2
-0.1               -0.3 and so on 

How do I randomly generate this?

I am not sure what you want, but this might help.

a=-.2:.1:2.2;
b=-3.2:.1:.2;
r1=randi(numel(a))
r2=randi(numel(b))
c=[a(r1) , b(r2)]

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

GK19
Sorry, Autocorrect!

How can I iterate all the values without using for loop?

Since there are many combinations I want to avoid for loop. Please let me know

On Mon, Jun 15, 2020 at 10:47 PM Ganesh Kini <[hidden email]> wrote:
Thank you

I can i iterate all the values without using for loop,

SInce there are many combinations I want to avoid for loop

On Mon, Jun 15, 2020 at 10:44 PM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 4:33 PM Ganesh Kini <[hidden email]> wrote:
I have 2 variables named A and B

A  has the range from -0.2 to 2.2 
B has the range from  -3.2 to 0.2

I need all the possible to combinations of A and B in 0.1 steps

for example 

A                        B
0.1                  0.2
-0.1               -0.3 and so on 

How do I randomly generate this?

I am not sure what you want, but this might help.

a=-.2:.1:2.2;
b=-3.2:.1:.2;
r1=randi(numel(a))
r2=randi(numel(b))
c=[a(r1) , b(r2)]

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

yamane
In reply to this post by GK19

On Mon, 15 Jun 2020, 21:33 Ganesh Kini, <[hidden email]> wrote:
I have 2 variables named A and B

A  has the range from -0.2 to 2.2 
B has the range from  -3.2 to 0.2

I need all the possible to combinations of A and B in 0.1 steps

for example 

A                        B
0.1                  0.2
-0.1               -0.3 and so on 

How do I randomly generate this?



Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

Doug Stewart-4
In reply to this post by GK19


On Mon, Jun 15, 2020 at 4:55 PM Ganesh Kini <[hidden email]> wrote:
Sorry, Autocorrect!

How can I iterate all the values without using for loop?

Since there are many combinations I want to avoid for loop. Please let me know

On Mon, Jun 15, 2020 at 10:47 PM Ganesh Kini <[hidden email]> wrote:
Thank you

I can i iterate all the values without using for loop,

SInce there are many combinations I want to avoid for loop

On Mon, Jun 15, 2020 at 10:44 PM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 4:33 PM Ganesh Kini <[hidden email]> wrote:
I have 2 variables named A and B

A  has the range from -0.2 to 2.2 
B has the range from  -3.2 to 0.2

I need all the possible to combinations of A and B in 0.1 steps

for example 

A                        B
0.1                  0.2
-0.1               -0.3 and so on 

How do I randomly generate this?

I am not sure what you want, but this might help.

a=-.2:.1:2.2;
b=-3.2:.1:.2;
r1=randi(numel(a))
r2=randi(numel(b))
c=[a(r1) , b(r2)]

--
DASCertificate for 206392


In your first question you hat the word "random" so I thought you wanted a random choice , in the range. 
Now I see that you don't wand random.
So what do you want? 
Just a set of all possible combinations? do you know how big that will be?

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

GK19
I want all the sets of randomly mixed values of A and B and then I need to iterate them
So, there are two questions 
1) How do I randomly pick one set of A and B and then pass it on the array?
2) How do I iterate all the sets of values without using for loop?  

On Mon, Jun 15, 2020 at 11:29 PM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 4:55 PM Ganesh Kini <[hidden email]> wrote:
Sorry, Autocorrect!

How can I iterate all the values without using for loop?

Since there are many combinations I want to avoid for loop. Please let me know

On Mon, Jun 15, 2020 at 10:47 PM Ganesh Kini <[hidden email]> wrote:
Thank you

I can i iterate all the values without using for loop,

SInce there are many combinations I want to avoid for loop

On Mon, Jun 15, 2020 at 10:44 PM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 4:33 PM Ganesh Kini <[hidden email]> wrote:
I have 2 variables named A and B

A  has the range from -0.2 to 2.2 
B has the range from  -3.2 to 0.2

I need all the possible to combinations of A and B in 0.1 steps

for example 

A                        B
0.1                  0.2
-0.1               -0.3 and so on 

How do I randomly generate this?

I am not sure what you want, but this might help.

a=-.2:.1:2.2;
b=-3.2:.1:.2;
r1=randi(numel(a))
r2=randi(numel(b))
c=[a(r1) , b(r2)]

--
DASCertificate for 206392


In your first question you hat the word "random" so I thought you wanted a random choice , in the range. 
Now I see that you don't wand random.
So what do you want? 
Just a set of all possible combinations? do you know how big that will be?

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

Doug Stewart-4


On Mon, Jun 15, 2020 at 5:43 PM Ganesh Kini <[hidden email]> wrote:
I want all the sets of randomly mixed values of A and B and then I need to iterate them
So, there are two questions 
1) How do I randomly pick one set of A and B and then pass it on the array?
2) How do I iterate all the sets of values without using for loop?  

On Mon, Jun 15, 2020 at 11:29 PM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 4:55 PM Ganesh Kini <[hidden email]> wrote:
Sorry, Autocorrect!

How can I iterate all the values without using for loop?

Since there are many combinations I want to avoid for loop. Please let me know

On Mon, Jun 15, 2020 at 10:47 PM Ganesh Kini <[hidden email]> wrote:
Thank you

I can i iterate all the values without using for loop,

SInce there are many combinations I want to avoid for loop

On Mon, Jun 15, 2020 at 10:44 PM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 4:33 PM Ganesh Kini <[hidden email]> wrote:
I have 2 variables named A and B

A  has the range from -0.2 to 2.2 
B has the range from  -3.2 to 0.2

I need all the possible to combinations of A and B in 0.1 steps

for example 

A                        B
0.1                  0.2
-0.1               -0.3 and so on 

How do I randomly generate this?

I am not sure what you want, but this might help.

a=-.2:.1:2.2;
b=-3.2:.1:.2;
r1=randi(numel(a))
r2=randi(numel(b))
c=[a(r1) , b(r2)]

--
DASCertificate for 206392


In your first question you hat the word "random" so I thought you wanted a random choice , in the range. 
Now I see that you don't wand random.
So what do you want? 
Just a set of all possible combinations? do you know how big that will be?

--
DASCertificate for 206392


This looks like homework.
I don't do homework questions.
I did show you how to do part of your question, and now I am out!

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

GK19
No sir, It is not. 

I can pass it via for loop but I don't want to take that approach.

Kindly let me know

On Tue, Jun 16, 2020 at 12:21 AM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 5:43 PM Ganesh Kini <[hidden email]> wrote:
I want all the sets of randomly mixed values of A and B and then I need to iterate them
So, there are two questions 
1) How do I randomly pick one set of A and B and then pass it on the array?
2) How do I iterate all the sets of values without using for loop?  

On Mon, Jun 15, 2020 at 11:29 PM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 4:55 PM Ganesh Kini <[hidden email]> wrote:
Sorry, Autocorrect!

How can I iterate all the values without using for loop?

Since there are many combinations I want to avoid for loop. Please let me know

On Mon, Jun 15, 2020 at 10:47 PM Ganesh Kini <[hidden email]> wrote:
Thank you

I can i iterate all the values without using for loop,

SInce there are many combinations I want to avoid for loop

On Mon, Jun 15, 2020 at 10:44 PM Doug Stewart <[hidden email]> wrote:


On Mon, Jun 15, 2020 at 4:33 PM Ganesh Kini <[hidden email]> wrote:
I have 2 variables named A and B

A  has the range from -0.2 to 2.2 
B has the range from  -3.2 to 0.2

I need all the possible to combinations of A and B in 0.1 steps

for example 

A                        B
0.1                  0.2
-0.1               -0.3 and so on 

How do I randomly generate this?

I am not sure what you want, but this might help.

a=-.2:.1:2.2;
b=-3.2:.1:.2;
r1=randi(numel(a))
r2=randi(numel(b))
c=[a(r1) , b(r2)]

--
DASCertificate for 206392


In your first question you hat the word "random" so I thought you wanted a random choice , in the range. 
Now I see that you don't wand random.
So what do you want? 
Just a set of all possible combinations? do you know how big that will be?

--
DASCertificate for 206392


This looks like homework.
I don't do homework questions.
I did show you how to do part of your question, and now I am out!

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

nrjank
Administrator
On Mon, Jun 15, 2020 at 6:25 PM Ganesh Kini <[hidden email]> wrote:
No sir, It is not. 

I can pass it via for loop but I don't want to take that approach.

Kindly let me know

as before, please post after the quoted reply, not before it. it makes it easier for readers to follow the conversation.

I assume you didn't actually mean 'randomly', but you are looking for all of the combinations. 

What you are doing looks like the generation of a 2d coordinate mesh, given vectors A and B.  You can use the meshgrid function to make all of those combinations.

>> A = 1:0.2:2;B = 10:0.2:11;[aa, bb] = meshgrid (A,B)
aa =

   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000

bb =

   10.000   10.000   10.000   10.000   10.000   10.000
   10.200   10.200   10.200   10.200   10.200   10.200
   10.400   10.400   10.400   10.400   10.400   10.400
   10.600   10.600   10.600   10.600   10.600   10.600
   10.800   10.800   10.800   10.800   10.800   10.800
   11.000   11.000   11.000   11.000   11.000   11.000


Now, the positions of aa and bb give you every combination of A, B.

if you want this reshaped as a single array, you could use:

>> C = [aa(:), bb(:)]
C =

    1.0000   10.0000
    1.0000   10.2000
    1.0000   10.4000
    1.0000   10.6000
    1.0000   10.8000
    1.0000   11.0000
    1.2000   10.0000
    1.2000   10.2000
    1.2000   10.4000
    1.2000   10.6000
    1.2000   10.8000
    1.2000   11.0000
    1.4000   10.0000
    1.4000   10.2000
    1.4000   10.4000
    1.4000   10.6000
    1.4000   10.8000
    1.4000   11.0000
    1.6000   10.0000
    1.6000   10.2000
    1.6000   10.4000
    1.6000   10.6000
    1.6000   10.8000
    1.6000   11.0000
    1.8000   10.0000
    1.8000   10.2000
    1.8000   10.4000
    1.8000   10.6000
    1.8000   10.8000
    1.8000   11.0000
    2.0000   10.0000
    2.0000   10.2000
    2.0000   10.4000
    2.0000   10.6000
    2.0000   10.8000
    2.0000   11.0000

Or however else you want to manipulate the array to make it useful for you.


Reply | Threaded
Open this post in threaded view
|

Re: Generation of random number which needs to be passed to an array

Doug Stewart-4


On Mon, Jun 15, 2020 at 10:42 PM Nicholas Jankowski <[hidden email]> wrote:
On Mon, Jun 15, 2020 at 6:25 PM Ganesh Kini <[hidden email]> wrote:
No sir, It is not. 

I can pass it via for loop but I don't want to take that approach.

Kindly let me know

as before, please post after the quoted reply, not before it. it makes it easier for readers to follow the conversation.

I assume you didn't actually mean 'randomly', but you are looking for all of the combinations. 

What you are doing looks like the generation of a 2d coordinate mesh, given vectors A and B.  You can use the meshgrid function to make all of those combinations.

>> A = 1:0.2:2;B = 10:0.2:11;[aa, bb] = meshgrid (A,B)
aa =

   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000
   1.0000   1.2000   1.4000   1.6000   1.8000   2.0000

bb =

   10.000   10.000   10.000   10.000   10.000   10.000
   10.200   10.200   10.200   10.200   10.200   10.200
   10.400   10.400   10.400   10.400   10.400   10.400
   10.600   10.600   10.600   10.600   10.600   10.600
   10.800   10.800   10.800   10.800   10.800   10.800
   11.000   11.000   11.000   11.000   11.000   11.000


Now, the positions of aa and bb give you every combination of A, B.

if you want this reshaped as a single array, you could use:

>> C = [aa(:), bb(:)]
C =

    1.0000   10.0000
    1.0000   10.2000
    1.0000   10.4000
    1.0000   10.6000
    1.0000   10.8000
    1.0000   11.0000
    1.2000   10.0000
    1.2000   10.2000
    1.2000   10.4000
    1.2000   10.6000
    1.2000   10.8000
    1.2000   11.0000
    1.4000   10.0000
    1.4000   10.2000
    1.4000   10.4000
    1.4000   10.6000
    1.4000   10.8000
    1.4000   11.0000
    1.6000   10.0000
    1.6000   10.2000
    1.6000   10.4000
    1.6000   10.6000
    1.6000   10.8000
    1.6000   11.0000
    1.8000   10.0000
    1.8000   10.2000
    1.8000   10.4000
    1.8000   10.6000
    1.8000   10.8000
    1.8000   11.0000
    2.0000   10.0000
    2.0000   10.2000
    2.0000   10.4000
    2.0000   10.6000
    2.0000   10.8000
    2.0000   11.0000

Or however else you want to manipulate the array to make it useful for you.

Great answer Nicholas!
Ganesh:  does this do what you want?

Do you still want any randomness ? 


--
DASCertificate for 206392