The IDL way: Find last non-zero value [message #67747] |
Sun, 23 August 2009 17:07 |
Eric Hudson
Messages: 19 Registered: June 2006
|
Junior Member |
|
|
Hi,
I have a 2D array that looks something like:
x x 0 x x 0 0 x 0 0 0 0 0
x 0 x x x 0 x x x x 0 0 0
x 0 0 0 0 0 0 0 0 0 0 0 0
x x x x x 0 0 0 0 0 0 0 0
where x is some non-zero (positive definite) value. You'll notice
that each row ends with a string of zeros.
What I'd like to know is the 'IDL way' of returning a vector of the
location (column) of the last non-zero elements in each row. So in
this case, [7,9,0,4]
It's straight forward to program with loops, but I figure there must
be a clever way. I thought that maybe reversing it and doing a
cumulative total might be a start, but then I can't convince myself
that that is really going to be faster than doing a loop.
For a sense of scale, the real array is something like 200 x 160000
Thanks,
Eric
|
|
|