Adding a dimension to a matrix in Matlab

I need to add a new matrix to a pre-existing matrix, but in its dimensional coordinate. I know this is hard to understand, so let's look at an example:

I have a matrix like this:

480x640x3 

And I want to add the following:

 480x640x6 

As a result, we get: (6 + 3 = 9)

 480x640x9 

As you can see, he adds, but in the third dimension.

+4
source share
2 answers

To concatenate to higher sizes, use the CAT function:

 newMatrix = cat(3,matrix1,matrix2); 
+8
source

I would say gnovice's answer is probably the best way to go, but you can do this too:

 matrix1(:,:,4:9) = matrix2; 
+5
source

Source: https://habr.com/ru/post/1380619/


All Articles