Search code examples
matlabmatrixoctaveoverlapping

Merger of Multiple matrices using Matlab/Octave


Assuming we have 3 matrices, A, B and C, all are of the same size 256x256. It is known that last 20% of columns of Matrix A is identical to first 20% of Matrix B and last 10% of Matrix B is identical to first 10% of Matrix C. So in these cases since we know the overlapping amount, I do not need to compare the 3 matrices, but i want to join them at the overlap.

Taking a smaller Matrix as an example here are the 3 Matrices

A = [1 2 3 4 ; 5 6 7 8; 9 10 11 12];
B = [3 4 13 14; 7 8 15 16; 11 12 17 18]; 
C = [14 19 20 21; 16 22 23 24; 18 25 26 27];

So I would like my output to be

D = [1     2     3     4    13    14    19    20    21
     5     6     7     8    15    16    22    23    24
     9    10    11    12    17    18    25    26    27

I hope this might explain it better. I am extremely new to matlab. I tried using matrix shift, but we have only circular shift available. Concatenation does not work because it just joins the 3 matrices. What would be the best way to overlay these 3 matrices together ?


Solution

  • Make proper use of matrix indexing and concatenation

    For your example

    D = [A B(:,3) C];
    

    For a 256x256 Matrix and your concatenation conditions:

    D = [A B(:, 0.2*256+1 : 0.9*256) C]
    

    Since 256/10 is no integer you may adjust the index values