X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 04 Apr 2011 05:53 AM by  anon
Vectors in "IF" condition
 4 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
04 Apr 2011 05:53 AM
    Hello, I have a simple line in my code: IF A EQ B THEN C=2 Variables A and B are vectors (of equal length), so the operator "EQ" also returns a vector, which "IF" statement does not want to accept. This is the error I've got from IDL: "% Expression must be a scalar or 1 element array in this context: ." Question: how it is possible to compare vectors and use the result as a condition in IF statement in IDL ??? Alexander

    Deleted User



    New Member


    Posts:
    New Member


    --
    05 Apr 2011 05:42 AM
    Dear Alexander, You may have a look on the "match2" function. -> http://idlastro.gsfc.nasa.../pro/misc/match2.pro With this function you can easily compare two vectors match2, A, B, va, vb test = where(va ne (-1), count) if count eq n_elements(A) then C = 2 Cheers, Vincent

    Deleted User



    New Member


    Posts:
    New Member


    --
    06 Apr 2011 05:38 AM
    Occasionally (as usual with IDL help), I found ARRAY_EQUAL function, which does the thing.

    Deleted User



    New Member


    Posts:
    New Member


    --
    11 Apr 2011 09:14 PM
    [QUOTE]Alexander_K wrote Occasionally (as usual with IDL help), I found ARRAY_EQUAL function, which does the thing. [/QUOTE] I agree with you. But what would be the next idea when you encountered it? I also thought about it but I still doubt. Frances Elaine Newton

    Deleted User



    New Member


    Posts:
    New Member


    --
    12 Apr 2011 03:20 AM
    Instead of using IF you might consider this example: A = [1,2,3] B = [3,2,1] print, (A eq B)*2 Hope this helps :)
    You are not authorized to post a reply.