| Re: Help assigning values to ranges of elements in an array??? [message #5199 is a reply to message #5196] |
Wed, 11 October 1995 00:00   |
nmw
Messages: 18 Registered: January 1995
|
Junior Member |
|
|
In article <45ff2r$n3f@mirv.unsw.edu.au>,
jgm@nntp.unsw.EDU.AU (Julian Marshall) writes:
> Hi.
> I was hoping someone could help me by suggesting a way by which
> I can assign values to a range of elements in an array. To be
> more exact, I want to make elements 0 to 100 (for eg.) of a
> 200 element array equal to a value or equal to values in a 100
> element array.
> Of course I can use for loops but I feel this is inefficient and
> a bit annoying when handling 256*256*256 bytarrs.
> IDL allows one to use an array operation to specify a range of
> values in an array (ie. A=B>10) but is it possible to use an
> array operation to specify a range of elements.
> Thanx
>
> julian
> jgm@newt.phys.unsw.edu.au
> ..
>
For your example you could simply do this (scaled down by 10 of course) :
IDL> a=indgen(20)
IDL> print,a
0 1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19
IDL> b=intarr(10)+999
IDL> a(0:9)=23
IDL> print,a
23 23 23 23 23 23 23 23 23 23 10
11 12 13 14 15 16 17 18 19
IDL> a(0:9)=b
IDL> print,a
999 999 999 999 999 999 999 999 999 999 10
11 12 13 14 15 16 17 18 19
IDL>
You can also do things like:
IDL> a=indgen(5,3)
IDL> print,a
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
IDL> a(3,*)=99
IDL> print,a
0 1 2 99 4
5 6 7 99 9
10 11 12 99 14
IDL> a(2:4,1)=0
IDL> print,a
0 1 2 99 4
5 6 0 0 0
10 11 12 99 14
IDL>
Or if you had something a bit more complicated in mind :
IDL> a=indgen(5,3)
IDL> b=[0,2,4]
IDL> a(b,1)=999
IDL> print,a
0 1 2 3 4
999 6 999 8 999
10 11 12 13 14
IDL>
--
Nigel Wade, System Administrator, Ionospheric Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555
|
|
|
|