I have a total of 4 column vectors which look like this:
m1: m2: m3: m4:
0.26 -0.25 0.04 0.43
-0.20 -0.12 0.50 0.47
-0.27 0.79 -0.37 0.29
-0.06 -0.45 -0.71 0.44
-0.23 0.13 0.31 0.52
0.87 0.29 0.02 0.23
I want to combine these 4 column vectors and put them in a single 6x4 matrix. How do I achieve this in JAMA? All four column matrices are of Matrix type.
Figured out the answer myself. Basically, we use a variant of the setMatrix()
method that has the following signature:
setMatrix(int[] r, int j0, int j1, Matrix X)
where,
r = array of row indices
j0 = initial column index
j1 = final column index
X = matrix you want to insert i.e. m1/m2/m3/m4 in my case
To set m1 in the first column of my matrix (say) meu, I can code it as follows:
int[] r = {0, 1, 2, 3, 4, 5) // since each of m1, m2, m3 and m4 have 6 rows
meu.setMatrix(r, 0, 0, m1); //sets submatrix m1 to 1st column (hence j0=j1=0)
To set m2 in the second column of my meu, I do:
meu.setMatrix(r, 1, 1, m2); //sets submatrix m2 to 2nd column
.... and similarly for the rest as well.