# How do I create a histogram out of this datastructure: x[i] = value_i?

Here is my SSCCE:

a[1] = 2; a[2] = 3; a[3] = 6; Histogram[a]


This throws and error though. Here are my questions:

1. What kind of data type is a? Is it an Array? a List? So far as I can tell it's neither.
2. How do I get the above to work?
-
Do you want an histogram or a bar chart? I suspect you want a bar chart, in which case a={2,3,6}; BarChart[a] – Cassini Nov 13 '12 at 1:56
And to answer your first question, a is a symbol. a={2,3,6} would be a list. – Cassini Nov 13 '12 at 1:57
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2)Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign – chris Nov 13 '12 at 7:04

These are DownValues. Lets say you defined a bunch of them as follows.

Table[a[i] =
RandomVariate[BinomialDistribution[100, 1/2]], {i, 10000}]


Applying DownValues to a gives the list you've created. Here is the first one.

DownValues[a] // First

(* HoldPattern[a[1]] :> 46 *)


You can similarly get them all at once and use Histogram on the values.

Histogram[ReleaseHold[First /@ DownValues[a]]]


-
Thanks for your response. What is the holding bit about? – David Nov 13 '12 at 2:08
DownValues uses HoldPattern so that it remains unevaluated. ReleaseHold does precisely what it says and releases the HoldPattern (and other types of held expressions). – Andy Ross Nov 13 '12 at 2:10
The following is worth reading. reference.wolfram.com/mathematica/tutorial/… – Andy Ross Nov 13 '12 at 2:12
Andy, any reason not to use Histogram[Last /@ DownValues@a]`? – Mr.Wizard Nov 13 '12 at 2:16
@David Is there a motivation for using this unconventional method for manipulating data? – image_doctor Nov 13 '12 at 8:53