Need some help understanding MATLAB `cat` command in high dimensions

Commands

a = magic(3);
b = pascal(3); 
c = cat(4,a,b);

      

produce a 3 by 3 array of 1 by 2.

Why the result 3-3-1-2

when the dimension 4

?

+2


source to share


1 answer


Both a

and b

are two-dimensional matrices of size 3 to 3. When you combine them in the fourth dimension, the third dimension is intermediate single point (i.e., 1). So it c(:,:,1,1)

will be your matrix a

, and it c(:,:,1,2)

will be your matrix b

.

Here's a link to some documentation that can help you understand multidimensional arrays.

EDIT:

Perhaps it helps to think about these four dimensions in terms that we humans can more easily relate to ...



Suppose the four dimensions in the example represent three dimensions in space ( x

, y

and z

) plus the fourth dimension of time. Imagine that I take the air temperature at several points in space at one time. I can sample the air temperature in a grid that contains all combinations of three positions x

, three positions y

and one position z

. This will give me a 3-by-3-by-1 grid. Usually we are probably just saying that the data is in a 3-by-3 grid, ignoring the final singleton dimension.

However, let's say that I will now take another set of samples at these points later. So I get another 3 by 3 by 1 grid at the second point in time. If I concatenate these datasets together by time size, I get a 3-by-3-by-1-by-2 matrix. The third dimension is single-point because I only chose one value z

.

So in the example, c=cat(4,a,b)

we are concatenating two matrices along the fourth dimension. Two 3-by-3 matrices, with the third dimension implicitly assumed to be one-point. However, when concatenating along the fourth dimension, we must explicitly show that the third dimension still exists by listing its size as 1.

+1


source







All Articles