Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?
share|improve this question
    
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] –  David Skulsky Nov 13 '12 at 1:56
    
And to answer your first question, a is a symbol. a={2,3,6} would be a list. –  David Skulsky 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

1 Answer 1

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]]]

enter image description here

share|improve this answer
    
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
1  
Andy, any reason not to use Histogram[Last /@ DownValues@a]? –  Mr.Wizard Nov 13 '12 at 2:16
1  
@David Is there a motivation for using this unconventional method for manipulating data? –  image_doctor Nov 13 '12 at 8:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.