Perhaps something like this is what you are looking for?

Suppose you have an array of objects. I have used the `Array`

function here, but the contents of this array could be anything.

```
elements = Array[a, {10}]
(*{a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10]}*)
```

Create a separate vector of energies. Since István has already shown the `NormalDistribution`

, I'll use `ExponentialDistribution`

.

```
energies = RandomVariate[ExponentialDistribution[1.5], {10}]
(*{0.0969302, 0.335765, 0.564123, 1.51769, 0.142579, 0.222407, \
0.842437, 1.35341, 0.239727, 0.0312016}*)
```

Now consider a function like this, which takes the index of the element and returns both the element and the associated energy. Notice that I have specified that `n`

has to be a positive integer, because indices of lists are always positive integers, and that it must also be less than the total length of the elements list.

```
getElement[n_Integer?Positive] /;
n <= Length[elements] := {elements[[n]], energies[[n]]}
getElement[4]
(*{a[4], 1.51769}*)
```

Because 20 is greater than the current length of `elements`

, `getElement[20]`

is undefined and returns itself unchanged.

```
getElement[20]
(* getElement[20] *)
```

But if you go back and redefine `elements`

(and `energies`

) to be longer, then re-evaluating `getElement[20]`

will return the 20th element-energy pair.

You could of course include some other checks to make sure that `energies`

is always the same length as `elements`

, but this should be enough to get you started.

**EDIT**

Based on your edit, it is possible that this is more appropriate. This function works out the position of the element in a particular vector, and returns that element and the matching element from the `energies`

vector.

```
getEnergyByElement[elem_, vec_?VectorQ] :=
With[{n = Position[vec, elem][[1, 1]]}, {vec[[n]], energies[[n]]}]
getEnergyByElement[a[4], elements]
(* {a[4], 1.51769} *)
```

An even simpler way is

```
{#, First@Pick[energies, elements, #]} &@a[5]
(*{a[5], 0.142579} *)
```

1Can you give a small example of what you want to see (say, for a ten-element array)? – J. M.'s ennui – 2012-07-05T09:59:07.000

1Daniel, if you will register you account it will be easier for you to edit your questions, post comments, etc. – Mr.Wizard – 2012-07-05T10:26:52.973

2Daniel, I see that you have already registered an account; I merged the temporary ones with this one. You should sign in before posting or editing. – Mr.Wizard – 2012-07-05T10:30:23.343

1You definitely don't need that

`For`

loop.`Xarray=A @@@ Tuples[Range[0, 9], 3]`

will do just as well, and it's much, much faster to type and to evaluate. – Verbeia – 2012-07-05T10:43:06.943Verbeia, Thanks for your wonderful suggestion. I have one doubt, In for loop program if I type Xarray[5], it will show the coordinates. How about this in your suggestion. – Daniel – 2012-07-05T10:49:23.667

@Daniel see my second answer which I have just posted. – Verbeia – 2012-07-05T11:42:04.483