Robert Cumming wrote:
> Once again, this is so basic I can't believe I can't work out how to do it.
>
> I have a set of data that I intend to make into (small) 2d piddles for
> contouring/image plotting. I have x, y, and z and the values of x and
> y are equally spaced.  I'm reading the data from a file which is not
> really rcol-able.
>
> How can I write directly to the elements of a 2d piddle?  index looks
> promising, but I'm not at all sure. I've scanning various docs and the
> PDL book but I think I've missed something basic.
>
> /Robert
>   
Unless there is some constraint you forgot to mention besides 
non-rcol-able data files, there are many ways to do this.  Usually you 
want some slicing operation, even if you have to assign to each element 
of a piddle individually.  For example, this works (assuming you're 
using PDL::NiceSlice):

(1+sequence(3,3))->wfits('a.fits'); #write some data to a file
$b = zeroes(10,10); #define a big array
$b(2:4,3:5).=rfits('a.fits'); #read into a portion of the array

Remember, the .= is key. Use = for assigning whole piddles, .= for 
assigning to subsets of piddles including single elements.  One thing 
you can NOT do that may at first seem reasonable is using the 'at' 
function, like

$b->at(2,3).=1; #wrong, 'at' does not return an lvalue
$b->(2,3).=1; #right

Index or index2d or indexND or range will work as well, as long as you 
remember the .= :
$b->index2d(7,8).=6; #single element assignment

or even an arbitrary set of locations
$b->index2d(pdl(1,2,6),pdl(7,4,9)).=10*(sequence(3)+1);

cheers,
Derek


_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to