How to concatenate these two arrays?

For example, I have two arrays A and B as below:

A = rand(5,3);
B = rand(5,3,2);

How do I concatenate them into C with the size of 5,3,3, so that:
C[:, :, 1] = A;
C[:, :, 2:3] = B;

Many thanks.

Maybe this:

C = [A;;; B]
3 Likes

Many thanks!

It works. However, my real world B has 50 layers, do I really need to add 50 semi-colons?

I can also add A to the end, but the below gives me an error.
C = [B; A];

Here is the error:
DimensionMismatch("mismatch in dimension 3 (expected 2 got 1)")

Please report real world size(A) and size(B)

Size(A) = 360x180
Size(B) = 360x180x50

My goal is to create a new array with the size of 360x180x51.

Thanks.

All good then, the result will have size(C) == (360, 180, 51)

1 Like

It works! Many thanks. :+1: