10128
How to duplicate a 2D matrix to build a 3D matrix
This Help Article explains how to build a 3D matrix by duplicating a 2D matrix, without using a loop in IDL.
An example 2D matrix (to be duplicated into a 3D matrix) is shown below:
b=[[1,2],[3,4]]
print,b
1 2
3 4
The following steps can be used to replicate this matrix 3 times in a 3D matrix:
Step 1: reform the 2D matrix B as a 1D vector
b=REFORM(b,4,1)
print,b
1 2 3 4
Step 2: create a 2D matrix by replicating 3 times the previous vector
b=b#REFORM(intarr(3)+1,1,3)
print,b
1 2 3 4
1 2 3 4
1 2 3 4
Step 3: reform the 2D matrix B as a 3D matrix
b=reform(b,2,2,3)
help,b
B LONG = Array[2, 2, 3]
print,b
1 2
3 4
1 2
3 4
1 2
3 4