I have 3 20x2 double
arrays A
, B
and C
. I want to combine them in one 3d array D
so that D(:,:,1)
will return A
, D(:,:,2)
will return B
and D(:,:,3)
will return C
.
Asked
Active
Viewed 3,500 times
3
-
possible duplicate of [How do I take a bunch of 2d matrices from .dat files and put them into one big 3d matrix?](http://stackoverflow.com/questions/16600582/how-do-i-take-a-bunch-of-2d-matrices-from-dat-files-and-put-them-into-one-big-3) – Mohsen Nosratinia Apr 24 '15 at 08:47
2 Answers
1
Like this?
A = 1*ones(20,2);
B = 2*ones(20,2);
C = 3*ones(20,2);
D = zeros(20,2,3); % Preallocate the D Matrix
D(:,:,1) = A;
D(:,:,2) = B;
D(:,:,3) = C;
D(1,1,1) % prints 1
D(1,1,2) % prints 2
D(1,1,3) % prints 3

Potaito
- 1,181
- 2
- 10
- 32