X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 12 Jul 2007 09:14 PM by  anon
where function help (beginner!)
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
12 Jul 2007 09:14 PM
    So I like the where function... it's pretty cool. got a question though, can I use it to search for array elements that contain a string? I have a structure with a couple of arrays, one of which contains dates in the form of 12-07-2007. So can I use the where function to search the array for all elements with a certain date? I was expecting to be able to do something like a=where(b.1 eq "07-07-2007") to get all the elements that contain that date, but it's not working - is the where function only useable with numerical data? if I can't do this with the where function, any suggestions of other methods?

    Deleted User



    New Member


    Posts:
    New Member


    --
    12 Jul 2007 09:14 PM
    Something looks wrong with the first element of your boolean expression argument to WHERE. What is "b.1" supposed to represent? In any case WHERE is used with strings all the time. Here is an example that demonstrates using it with precisely formatted date strings like yours: IDL> seed = 1L ; Make a pseudorandom set of dates IDL> randomDaysIn2007 = julday(1,1,2007) + fix(randomu(seed, 16) * 365) IDL> ; Store them as strings in precise MM-DD-YYYY format IDL> myDates = string(randomDaysIn2007, FORMAT='(C(CMoI02, "-", CDI02, "-", CYI4))') IDL> print, myDates, FORMAT='(4A12)' ; Here are our 16 data elements ; 06-01-2007 02-03-2007 10-04-2007 07-13-2007 ; 12-06-2007 05-20-2007 08-27-2007 01-25-2007 ; 09-21-2007 09-02-2007 05-20-2007 08-19-2007 ; 11-19-2007 07-09-2007 08-26-2007 03-28-2007 IDL> print, where(myDates eq '03-28-2007') 15 IDL> ; I can even search for substrings. Here I am looking for dates with the 19th day IDL> print, where(strmid(myDates, 3, 2) eq '19') ; 11 12 James Jones
    You are not authorized to post a reply.