comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » help with sorting vector elements in to subarrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
help with sorting vector elements in to subarrays [message #80234] Mon, 21 May 2012 07:33 Go to next message
Tito is currently offline  Tito
Messages: 16
Registered: March 2012
Junior Member
Hallo!

I have this vector: zz = [5,6,9,10,11]

Anybody can tell me how I can sort it like zz1 = [5,6], zz2 =[9,10,11]?

Here is the code:

zz =[]
f=indgen(n_elements(amp))

;;I have amp[i] on witch some of the elements are identical.
;I need to take this [i]indexies and
;1-st to take it out
;2nd to write it to another array [sub arrays]

for i=0L, n_elements(amp)-1 do begin
a = where(amp[i] eq amp ,count)
if count gt 0.0 then begin
if n_elements(a) gt 1 then begin
zz = [zz,i]
endif
endif
endfor

if n_elements(zz) ne 0.0 then begin
match2,f,zz,subf,subzz
f[subzz] = -1
f = f[where(f[*] NE -1)]
endif

zz = Long[5]
4 5 9 10 11

f = Int[13]
0 1 2 3 6 7 8 12 13 14
15 16 17

All the best,
Trifon
Re: help with sorting vector elements in to subarrays [message #80447 is a reply to message #80234] Thu, 31 May 2012 07:49 Go to previous message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
If you want to record the sequences, the tricky part is to deal with their variable lengths. If you're using 8.x, you could try putting them in a list:

sequence=list()

then...
sequence.add,where(ss[i] eq amp)

print,sequence[i]

Or the older way was to use an array of pointers:

sequence=ptrarr(n_elements(ss))

...
sequence[i]=ptr_new(where(ss[i] eq amp))

print,*sequence[i]

greg
Re: help with sorting vector elements in to subarrays [message #80448 is a reply to message #80234] Thu, 31 May 2012 06:53 Go to previous message
Tito is currently offline  Tito
Messages: 16
Registered: March 2012
Junior Member
On Thursday, May 31, 2012 2:36:29 PM UTC+2, (unknown) wrote:
> Would this do it?
>
> for i = 0L, n_elements(ss)-1 do print,where(ss[i] eq amp)
>
> greg

Thanks for the fast answer Greg!

I all ready did something similar with:

for i = 0L , n_elements(ss)-1 do begin
a = where(ss[i] eq amp,count)
dd[i,a] = a
endfor

I just wanted to record this indexies in seperate arrays and use it later on.
But you are right... why not use it inside the loop???

For example:

for i = 0L, n_elements(ss)-1 do begin
a = where(ss[i] eq amp,count)
for ii = 0L, n_elements(a)-1 do spec = spec - (amp[a[ii]]*exp((-1d0*(wave-line[a[ii]])^2d0)/var[a[ii]]))/n _elements(a)
endfor

I think I will be fine from now on....

Any way is there a way how to extract the neeeded data from ;; Now dd = Double[3, 20]
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
3.0000000 -1.0000000 -1.0000000
4.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 6.0000000 -1.0000000
-1.0000000 7.0000000 -1.0000000
-1.0000000 8.0000000 -1.0000000
-1.0000000 -1.0000000 9.0000000
-1.0000000 -1.0000000 10.000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
??? Just want to know.....
All the best!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: help with mathematics
Next Topic: put a variable in 2D-array to plot a contour on a map.

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:44:02 PDT 2025

Total time taken to generate the page: 0.00547 seconds