Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

histogram

0 views
Skip to first unread message

Michael Probst

unread,
Sep 23, 1995, 3:00:00 AM9/23/95
to
Hi !
I have a rather simple mma - question:
What is the best (fastest) way to generate histograms ?
That is: I have a list of data and I want to fill the data
into another list which elements are zero at the beginning
and are incramanted by one if the data is in the interval
corresponding to the respective element of the second list
which is just the histogram.
I can use a Do[] but this seems clumsy:
hist={0,0,0, .... };
Do[
ind=myindexfunction[data[[i]]]; hist[[ind]]=hist[[ind]]+1,
{i,1,Length[data]}]

Thanks a lot !
Michael

michael...@uibk.ac.at

Dave Wagner

unread,
Sep 24, 1995, 3:00:00 AM9/24/95
to
In article <DFCF7...@wri.com>,

Michael Probst <michael...@uibk.ac.at> wrote:
>What is the best (fastest) way to generate histograms ?

>I can use a Do[] but this seems clumsy:


>hist={0,0,0, .... };
>Do[
> ind=myindexfunction[data[[i]]]; hist[[ind]]=hist[[ind]]+1,
>{i,1,Length[data]}]
>

You can use Scan on your data:

Scan[hist[[myindexfunction[#]]]++ &, data]

The ++ operator takes the place of the addition and assignment.
Thus you don't need a local variable for the index anymore.

Dave Wagner
Principia Consulting
(303) 786-8371
dbwa...@princon.com
http://www.princon.com/princon


0 new messages