user1030373
user1030373

Reputation: 75

Adding a dimension to a matrix in Matlab

I need to add a new matrix to a previously existant matrix, but on his dimension coordinate. I know this is hard to understand, so let's see it on a example:

I've a matrix like this:

480x640x3

And I want to add the following one:

480x640x6

The result has be this: (6+3 = 9)

480x640x9

As you can see it adds but on the 3rd dimension.

Upvotes: 4

Views: 12952

Answers (2)

Jim Clay
Jim Clay

Reputation: 1003

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

matrix1(:,:,4:9) = matrix2;

Upvotes: 5

gnovice
gnovice

Reputation: 125874

For concatenating along higher dimensions, use the function CAT:

newMatrix = cat(3,matrix1,matrix2);

Upvotes: 9

Related Questions