X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 28 Oct 2008 07:02 PM by  anon
how to store vectors of different lengths in one variable
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
28 Oct 2008 07:02 PM
    Hi guys,     I am a new learner. I need a variable, which can be an array or anything, to contain 14 vectors with different lengths. if they are of equal length l, I can simply build an 14 * l array      I can run a loop 14 times to process these vectors, but that is definitely nor a good solution. Thanks for your advice  

    Deleted User



    New Member


    Posts:
    New Member


    --
    02 Dec 2008 01:33 AM
    (reformatted version of original post: apparently, rich text formatting is obligatory!)   for this you can try an array of pointers:   --------   ; pointer array of 14 rows. allocate pointers, so you can assign them right away. p = ptrarr(14, /alloc)   ; first row: 100 longs *p[0] = lonarr(100)   ; second row: 20 floats *p[1] = fltarr(20)   ; add 1 to all elements of first row (*p[0]) += 1   ; print first row print, 'first row = ', *p[0]   ; assign function to the 20 floats in the second row (*p[1]) += findgen(20)^1.5   ; print second row print, 'second row = ', *p[1]   ; assign new row array to first row.. let's say a 150 doubles *p[0] = dblarr(150)   ; print first row print, 'first row = ', *p[0]   ; what pointers do we have now? help, /heap   ; free pointer array and give back memory to the system ptr_free, p   ; what pointers do we have now? (should be none) help, /heap   --------   hope this helps,   Pieter van der Meer SRON - Netherlands Institute for Space Research  
    You are not authorized to post a reply.