Re: printing an array from pointers [message #48093] |
Tue, 28 March 2006 21:08  |
bressert@gmail.com
Messages: 8 Registered: February 2006
|
Junior Member |
|
|
Hi Peter,
Thanks for the tip on fltarr, worked like a gem. This is my first
project in IDL and I have a lot to cover still. When I initially made
the current program I was used to loops and realized towards the end
that using arrays is much more efficient. For the next script, I will
try that out.
Cheers,
Eli
|
|
|
Re: printing an array from pointers [message #48121 is a reply to message #48093] |
Tue, 28 March 2006 05:30   |
peter.albert@gmx.de
Messages: 108 Registered: July 2005
|
Senior Member |
|
|
Hi Eli,
if your goal really is to just create the 10x8 array via the loop and
then print the complete array, I wouldn't use pointers. A simple
arr = fltarr(10,8)
for i = 0,9 do begin
...
arr[i,*] = (some 1 by 8 vector)
endfor
print, arr
will do the trick.
If you _really_ want to use the pointer array, you have to manually
concatenate the individual vectors like
print, transpose([[*ptr[0]], [*ptr[1]], ..., [*ptr[9]]])
which is far from being elegant and most likely will waste some memory.
Not really a problem with 10x8 entries, but there is probably more to
come?
While you think over it, why not completely re-thinking the problem and
trying to avoid the for-loop at all :-) ?
Cheers,
Peter
|
|
|
|
Re: printing an array from pointers [message #48190 is a reply to message #48121] |
Tue, 28 March 2006 23:55  |
bressert@gmail.com
Messages: 8 Registered: February 2006
|
Junior Member |
|
|
Hi Peter,
Another question, since I have ran into a new bump. Is there a way to
say
arr = fltarr(A,8)
where A is a number that fluctuates? So rather than stating that arr is
A rows long, it is a number determined by the total output of the for
loop? For example,
arr = fltarr(150,8)
will be sufficient in gathering all the 'for' outputs, but I will have
trailing zeros that have not been assigned an output value. Using UNIQ
or an 'if' to get rid of the zeros in the array does not work, since
some of the output from the 'for' loop is zero. This was the original
reason why I used the pointers, since there was no requirement of
predetermination of the number of rows. Any suggestions or ideas would
be greatly appreciated. Thanks again for the help.
Cheers,
Eli
|
|
|