Features of the colon operator [message #94388] |
Sun, 07 May 2017 04:10 |
Matthew Argall
Messages: 286 Registered: October 2011
|
Senior Member |
|
|
An interesting feature of the colon operator caught me by surprise. Using the two examples from the IDL help page
www.harrisgeospatial.com/docs/Creating_Arrays.html
IDL> Help, [[1:5], [6:10], 11, [11:16], 17, 18, 19, 20, [21:30]]
<Expression> INT = Array[31]
IDL> Help, [[10:19], [20:29], [30:39]]
<Expression> INT = Array[10, 3]
The first example results in an Nx1 array while the second example results in an Nx3 array despite the similarity in appearance. The latter is consistent with non-colon-operator array concatenation, the former is not. It gets more complicated when I want to combine an Nx1 with an Mx1 array to get an Lx1 array.
IDL> Help, [ 0:10:0.1, 0:10:0.5 ]
^
% Illegal array creation syntax.
IDL> Help, [ [0:10:0.1], [0:10:0.5] ]
% Unable to concatenate variables because the dimensions do not agree: <FLOAT Array[21]>.
% Execution halted at: $MAIN$
To get the Lx1 array, I have to do one of the following
IDL> Help, Reform( [ [Transpose([0:10:0.1])], [Transpose([0:10:0.5])] ] )
<Expression> FLOAT = Array[122]
IDL> Help, [ [0:10:0.1], !Null, [0:10:0.5] ]
<Expression> FLOAT = Array[122]
|
|
|