Re: Create new arrays from series of subsequent integers in an existing array [message #48812 is a reply to message #48797] |
Tue, 23 May 2006 15:55   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Jonathan Wolfe writes:
> Thank you both for your help! In regards to JD's saving the output
> arrays with pointers... I have never used pointers and believe this is
> a case in which they are necessary.
>
> After writing a long, drawn out explanation of where I was stuck with
> pointers I ended up figuring them out. Just in case anyone new to
> pointers wants to know how to get variables from an example such as the
> above threads, use something like this:
>
> x= ptrarr(3)
>
> for i = 1L, n_elements(h) - 1L do begin
> t=ri[ri[i]:ri[i+1]-1]
> x[i] = PTR_NEW( t,/allocate_heap )
> endfor
>
> print,*x(2)
>
> and you will have your varying size arrays of a larger array segmented
> into different subscripts of x.
>
> I'm sure there may be a better way to do this, but it makes sense to me.
I wrote up a slightly different method on my web page:
http://www.dfanning.com/idl_way/avgseries.html
Be sure you free up your pointers when you are finished with them:
Ptr_Free, x
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|