Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
Identifying the index of a repeated element in an array
Hello everybody, I have an array that looks like this: x = [1,2,3,4,5,0,1,2,0,0,0,0,1,2,3,0,0,0,1,2,3] I am interested in the location of the element "5" (index 4), "3" (index 14), and "3" (index 20). I am writing a program to output the above three indices. However, using min(where(x eq 3)) keeps giving me the index of the first 3, which I do not want. I need the index of the second 3, and the third 3. Is there any way to do this? Thank you so much!
Re: Identifying the index of a repeated element in an array
On 6/20/17 2:49 pm, thtran296@gmail.com wrote: > Hello everybody, > > I have an array that looks like this: > x = [1,2,3,4,5,0,1,2,0,0,0,0,1,2,3,0,0,0,1,2,3] > I am interested in the location of the element "5" (index 4), "3" (index 14), and "3" (index 20). > I am writing a program to output the above three indices. > However, using min(where(x eq 3)) keeps giving me the index of the first 3, which I do not want. > I need the index of the second 3, and the third 3. > > Is there any way to do this? > > Thank you so much! > I'm not sure of your question. Here is the answer to your question as stated: ind = where(x eq 3) print, ind[1], ind[2] Is this what you need? Mike -- Michael Galloy www.michaelgalloy.com Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)