1

I would like to know how to generate a 3-d array from a 2-d array in matlab. My lack of understanding may simply be the result of not knowing the correct nomenclature.

I have a 2-dimensional array or matrix, A:

A = [12, 62, 93, -8, 22; 16, 2, 87, 43, 91; -4, 17, -72, 95, 6] 

and I would like to add a 3rd dimension with the same values such that:

A(:,:,1) = 12    62    93    -8    22
           16     2    87    43    91
           -4    17   -72    95     6

and

A(:,:,2) = 12    62    93    -8    22
           16     2    87    43    91
           -4    17   -72    95     6

to

A(:,:,p) = 12    62    93    -8    22
           16     2    87    43    91
           -4    17   -72    95     6

how would I go about doing so in the most efficient way (I might have a much larger array where m = 100, n = 50, p= 1000 where A(m,n,p).

1
  • type "doc repmat" in your Matlab command window, i do not know if it is the most efficient, but the resulting code will be easy to read and understand. Commented Dec 9, 2014 at 10:07

1 Answer 1

2

Try

 result = reshape(repmat(A,1,p),m,n,p)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.