Problem solved by Sean de and Matt Fig.
Guys is it possible to modify the code to support this kind of matrix?
A=reshape(1:45,3,5,3);
B=reshape(1:105,5,7,3)+45;
The merging still same as before. Superimpose base location on Matrix A and Matrix B. However now there is 3 level of array. (i thinks its call 2 dimensional array, not very sure though)
i could store each level of array into separate 1 dimensional array and use the code u guys written to combine the matrix then put the matrix back into a new 2 dimensional array. But that means i need to run through the code 3 times.