Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a dimension to a matrix in Matlab

Tags:

matrix

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.

like image 383
user1030373 Avatar asked Dec 09 '22 04:12

user1030373


2 Answers

For concatenating along higher dimensions, use the function CAT:

newMatrix = cat(3,matrix1,matrix2);
like image 65
gnovice Avatar answered Dec 17 '22 18:12

gnovice


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;
like image 31
Jim Clay Avatar answered Dec 17 '22 17:12

Jim Clay