X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 08 Jul 2019 02:15 PM by  Ben Castellani
Math operations on arrays of different dimensions
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Ben Castellani



Basic Member


Posts:130
Basic Member


--
08 Jul 2019 02:00 PM
    Is it possible for IDL to produce an error message and stop the code if mathematical operations are attempted on arrays of different lengths?

    Here is an example?

    IDL> a = lindgen(10)
    IDL> b = intarr(2) + 1

    IDL> help, a, b, a/b, a*b, a+b
    A LONG = Array[10]
    B LONG = Array[2]
    LONG = Array[2]
    LONG = Array[2]
    LONG = Array[2]

    Ben Castellani



    Basic Member


    Posts:130
    Basic Member


    --
    08 Jul 2019 02:15 PM
    Unfortunately, this is the expected behavior of IDL and there is no way to force this to procude an automatically. You would need to manually check array lengths before performing the math operations. For example:

    a = lindgen(2)
    b = intarr(2) + 1
    if n_elements(a) ne n_elements(b) then message,"Array dimensions not equal" else c = a+b
    You are not authorized to post a reply.