| Re: Q:assigning arrays in steps [message #4162] |
Wed, 10 May 1995 00:00 |
Fergus Gallagher
Messages: 41 Registered: January 1995
|
Member |
|
|
Brett Hennig <bretth@lovelace.maths.monash.edu.au> wrote:
> I've been using idl for one whole week now,
> so excuse me if this question is stupid.
> In Fortran90 you can assign arrays like:
> x(0:10)=y(0:40:4)
> where the last 4 is a step increment.
>
> Can this sort of stuff be done with idl?
>
G'day,
Easily (not as elegant as F90, but more flexible).
You can index any elements of an array with another array. In your case:
IDL> x(0:10) = y(indgen(11)*4)
In 2D, this must be a two stage process, since, for example
x(0:10,0:10) <> x(indgen(11),indgen(11))
The latter is the vector
[x(0,0), x(1,1), x(2,2),....x(10,10)]
so you would have to write the assignment as:
IDL> tmp = y(indgen(11)*4,*) ; 11xN
IDL> x(0:10,0:10) = tmp(*,indgen(11)*4); 11x11
An additional point: you can insert an array into another (larger) array
just by specifying the offset, without the range. For example, the last
assignment above could have be written as;
IDL> x(0,0) = tmp(....)
which obviously generalises to abitrary offsets.
Fergus
=================================================
| Fergus Gallagher |
| Remote Sensing Applications Development Unit |
| British National Space Centre |
| Monks Wood |
| Huntingdon PE17 2LS / UK |
| |
| F.Gallagher@nerc.ac.uk |
| http://uh.nmt.ac.uk/bnsc/fgg.html |
=================================================
|
|
|
|
| Re: Q:assigning arrays in steps [message #4173 is a reply to message #4162] |
Mon, 08 May 1995 00:00  |
korpela
Messages: 59 Registered: September 1993
|
Member |
|
|
-----BEGIN PGP SIGNED MESSAGE-----
In article <3oikmj$mru@harbinger.cc.monash.edu.au>,
Brett Hennig <bretth@lovelace.maths.monash.edu.au> wrote:
> In Fortran90 you can assign arrays like:
> x(0:10)=y(0:40:4)
> where the last 4 is a step increment.
>
> Can this sort of stuff be done with idl?
You could do it this way.....
x(0:10)=y(indgen(11)*4)
A more generic way would be to write a function that returns a range
x(0:10)=y(range(0,40,4))
in fact, here's one now....
- ------------------------------------------------------------ ------------------
Function range,lo,hi,delta
if (n_params(0) lt 2) or (n_params(0) gt 3) then begin
print,'RANGE-- Incorrect number of parameters'
return,-9999.0
endif
if (n_params(0) eq 2) then delta=1.0
number=long((float(hi)-float(lo))/float(delta))+1
outrange=float(lo)+findgen(number)*float(delta)
return,outrange
end
- ------------------------------------------------------------ ------------------
-----BEGIN PGP SIGNATURE-----
Version: 2.6
iQCVAwUBL65zkOBZ/OT/DJLdAQHwtQP/RiHqWcmZVhz20xiNdi82Y80KZyww PhNP
Vg9Nj3Vqv9sBSS+oL5xdOaESLsgkgnhldIBEGlkC5q5eTuSXz7ZaRWRLngL4 +q6n
dILsQJ+Aj63QtA8MXT/XFfjoQ4HzxuMP/1rD7S50q57tjdfL3538s3/A8Sa4 c591
S/0UE6nOcGY=
=9iTd
-----END PGP SIGNATURE-----
--
Eric Korpela | A day without meetings is like
korpela@ssl.berkeley.edu | work.
<a href=" http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpe la/w">Click here for more info.</a>
|
|
|
|
| Re: Q:assigning arrays in steps [message #4176 is a reply to message #4173] |
Mon, 08 May 1995 00:00  |
peter
Messages: 80 Registered: February 1994
|
Member |
|
|
Brett Hennig (bretth@lovelace.maths.monash.edu.au) wrote:
: I've been using idl for one whole week now,
: so excuse me if this question is stupid.
: In Fortran90 you can assign arrays like:
: x(0:10)=y(0:40:4)
: where the last 4 is a step increment.
: Can this sort of stuff be done with idl?
x(0:10) = y(4*indgen(11))
More generally, arrays can be addressed using another array, which will
extract specified elements. Very powerful!
Peter
|
|
|
|