How can I create a 3-d matrix from a 2-d matrix?

My matrix is an 11x14 matrix and I would like to create 2 more "pages" behind the original of the same values for a total of 3 "pages". Is there an efficient way of doing this? This needs to be done for several matrices.

 Accepted Answer

Another way is to use cat(3,...) instead of repmat():
output = cat(3, myMatrix, myMatrix, myMatrix);
or "If I have the A(:,:,2) matrix and want to replicate those values into A(:,:,1) and A(:,:,3),"
A(:,:,1) = A(:,:,2);
A(:,:,3) = A(:,:,2);

More Answers (1)

repmat(A,1,1,3)

4 Comments

This did not help. In fact I'm not even sure what this did. Lets say I have an existing 3x3 matrix 'A' of zeros. I would like to repeat that matrix two more times in the k dimension so that I can use the A(:,:,2) matrix to add, subtract, multiply and divide with the A(:,:,1) and A(:,:,3) its sandwiched in between. Thanks
It did what you asked
A=zeros(3,3)
B=repmat(A,1,1,3)
Thank you! Another question if you don't mind. If I have the A(:,:,2) matrix and want to replicate those values into A(:,:,1) and A(:,:,3), how would I do that?
What difference does it make if all three levels end up the same?

Sign in to comment.

Tags

Asked:

on 12 Jun 2016

Commented:

on 13 Jun 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!