MATLAB: How to vertically concatenate matrices inside a matrix

concatenatematrices

Lets say have 2 matrices (A and B), Both A and B have 2 matrices inside (A1,A2 and B1, B2).
A=1×2
A1=1×20, A2=1×20
A1,1=10×1 A1,2=10×1 A1,3=10×1 A1,4=10×1… and so on until A1,20. Basically 20 columns of 10 rows
A2,1=20×1 A2,2=20×1 A2,3=20×1 A2,4=20×1… and so on until A2,20. Basically 20 columns of 20 rows
B=1×2
B1=1×20, B2=1×20
B1,1=30×1 B1,2=30×1 B1,3=30×1 B1,4=30×1… and so on until B1,30. Basically 20 columns of 30 rows
B2,1=40×1 B2,2=40×1 B2,3=40×1 B2,4=40×1… and so on until B2,30. Basically 20 columns of 40 rows
I would like to have a matrix called M with 2 matrices inside (M1 and M2). So that I have:
M=1×2
M1=1×20
M1,1= 40×1 M1,2=40×1 M1,3=40×1 M1,4=40×1…Basically 20 columns of 40 rows
M2=1×20
M2,1= 60×1 M2,2=60×1 M2,3=60×1 M2,4=60×1…Basically 20 columns of 60 rows
I know it sounds complicated but basically I need to concatenate into 1 matrix with 2 matrices inside of 40×20 and 60×20. Thank you!

Best Answer

You seem to have nested cell arrays, so perhaps this might work:
cellfun(@(a,b)cellfun(@vertcat,a,b,'uni',0),A,B,'uni',0)