[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Incrementing an Array




s007amf@news.wright.edu (ALAN FRAZIER) writes:


> Once again I am struggling with the finer points of IDL.  What I am trying 
> to do seems simple, but is causing me some headaches.  What I am trying to 
> do is this:
> 
> matrix[x,y,z] = matrix[x,y,z] + 1
> 
> Where matrix is a 3D array and x,y,z are 1D arrays.  Matrix starts out 
> all 0's and I am trying to increment values at elements [x,y,z].  The 
> problem 
> is that some elements should be incremented multiple times.  All the 
> proper elements are incremented once, but the second, third, 
> fourth....increments are not showing up.  Any ideas?  I know that I could 
> write this with loops, but that would be too slow.

This is a common error using array indices.  The problem is that each
element evaluated in parallel, not in sequence.

You really want to use HISTOGRAM for this one.  JD Smith wrote an
n-dimensional histogramming function which you can find here:

http://cow.physics.wisc.edu/~craigm/idl/archive/msg05549.html

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------