I donβt think you need a 3D matrix. I would suggest the following options:
Option 1. Cell Cell
>> A = rand(5,10); B = rand(5,6); >> {A, B} ans = [5x10 double] [5x6 double]
Option 2. Cell Cell
>> clear C; for i=1:5, C{i,1} = A(i,:)'; C{i,2} = B(i,:)'; end; C C = [10x1 double] [6x1 double] [10x1 double] [6x1 double] [10x1 double] [6x1 double] [10x1 double] [6x1 double] [10x1 double] [6x1 double]
Option 3. Concentrate the arrays, and then just index the parts that you need.
>> C = [A,B]; size(C) ans = 5 16
Option 4. Use a structural array
>> clear C; for i=1:5, C(i).A = A(i,:)'; C(i).B = B(i,:)'; end; C C = 1x5 struct array with fields: A B
If you think of a 3D matrix as a cube and a 2D matrix as a square, you should see that what you are trying to do is create a cube of two squares, leaving the cube volume empty (just like the other four sides).
source share