Help!

randomly picking up an array element from an array of elem..

 
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> General Discussions RSS
Next:  Deleting A COLUMN BY MACRO  
Author Message
Sanjog
External


Since: Aug 08, 2012
Posts: 1



PostPosted: Wed Aug 08, 2012 10:10 am    Post subject: randomly picking up an array element from an array of elements
Archived from groups: microsoft>public>excel>misc (more info?)


I have an array of x,y points which are inputted in a single cell
for example
array 1 = (0.2,0.4) , (0.23,0.34),(.87,.32),(-.33,-.54).... there are
such 50 points in array 1.

There are different numeric triggers which are matched with the arrays.
For example
trigger 1 = array 1
trigger 2 = array 2
so on...

When the event trigger 1 = array 1 is true then I want to read these 50
points in array 1 and randomly pick one set of (x,y) and write the value
in a different cell. How to do that in excel ?




--
Sanjog
Back to top
James Ravenswood
External


Since: Jun 16, 2010
Posts: 11



PostPosted: Wed Aug 08, 2012 11:01 am    Post subject: Re: randomly picking up an array element from an array of elements [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

If the points are stored in cells A1 thru A50, then to pick one fo these at random:

=INDEX(A1:A50,RANDBETWEEN(1,50),1)
Back to top
joeu2004
External


Since: Jul 13, 2011
Posts: 50



PostPosted: Wed Aug 08, 2012 3:04 pm    Post subject: Re: randomly picking up an array element from an array of elements [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Sanjog" wrote:
> I have an array of x,y points which are inputted in a single cell
> for example
> array 1 = (0.2,0.4) , (0.23,0.34),(.87,.32),(-.33,-.54)....
> there are such 50 points in array 1.

You clearly explained that all 50 coordinates (x-y pairs) are in a
__single_cell__, not an array of cells.

That is unfortunate. Since the coordinates seem to have a variable form, I
think it would be easier to use VBA to parse the "array" of coordinates.


"Sanjog" wrote:
> There are different numeric triggers which are matched with the arrays.
> For example
> trigger 1 = array 1
> trigger 2 = array 2
> so on...
> When the event trigger 1 = array 1 is true then I want to read
> these 50 points in array 1 and randomly pick one set of (x,y)
> and write the value in a different cell. How to do that in excel ?

The fastest way to get an applicable solution to your problem is to write
examples in the language you are talking about, namely Excel formulas and
cell references or VBA.

I have no idea what you mean by "event trigger 1 = array 1".

Suppose "array 1" is in A1, "array 2" is in A2 etc up to "array 10" in A10,
and the trigger is the value 1, 2 etc up to 10 in B1.

Then you might write:

=randCoord(INDEX(A1:A10,B1))

where randCoord is the following VBA function:

Option Explicit

Function randCoord(arr As String)
Dim n As Long, x As Long, v As Variant
v = Split(arr, ",") ' v(0),v(1),...,v(n-1)
n = UBound(v)
x = Int((n \ 2) * Rnd())
randCoord = Trim(v(2 * x)) & "," & Trim(v(2 * x + 1))
End Function

Note: This does not ensure unique random selection. You did not ask for
that.
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> General Discussions All times are: Eastern Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum