Search code examples
matlabmatrixvectorcamera-calibrationrotational-matrices

How to combine rows from different matrices


I calibrated ten images and got the translation vectors and rotation vectors of it.

V = cameraParams.TranslationVectors (3X10) 
R = cameraParams.RotationVectors; (3X10)

How can I assign ten [1x6] matrix by taking three from V and 3 from R (respective images) for all ten components.

Example:

V = 
1 2 3 
4 5 6
7 8 9
. . .
. . .

R = 
11 12 13 
14 15 16
17 18 19
.  .  .
.  .  .

Final = 
1 2 3 11 12 13
4 5 6 14 15 16
. . .  .  .  .  
. . .  .  .  .
V = cameraParams.TranslationVectors
V(:,1) %Reading 1st row
A(1) gives the first value

But how can I do it effectively?


Solution

  • What you want is to Concatenate arrays horizontally. The can be done using one of the approaches below:

    Final = [V, R]
    Final = [V R]
    Final = horzcat(V, R)
    Final = cat(2, V, R)    % Concatenate along the second dimension
    

    The first one is the most common one. The third is probably easiest to read for people that are not used to MATLAB syntax. The fourth approach is usually only used if you want to concatenate matrices along dimensions 3 ... N, i.e. not horizontally or vertically.