Hey all, had a quick question

Say I have a few 3d arrays with dimensions of 240x40x8094. Let's call them x,y,z and w. How can I put them together into a matrix of 240x40x32376 called say t?

For instance, I want them to be put together in such a way as

(1,1,t1) = (1,1,x1)

(1,1,t2) = (1,1,y1)

(1,1,t3) = (1,1,z1)

(1,1,t4) = (1,1,w1)

(1,1,t5) = (1,1,x2)

(1,1,t6) = (1,1,y2)

etc, where x1,y1,z1,x2 is the time dimension in increasing order

The first two dimensions are the same for each matrix

Here is what I have tried so far with no luck. The first part is initializing the arrays. The 'cat' variables are the arrays just appended to each other ie

(1,1,tcat1) = (1,1,x1)

(1,1,tcat2) = (1,1,x2)

.

.

(1,1,tcat8095) = (1,1,y1)

etc

The t_cat matrix is what I expect. The t matrix is not

The third dimension is time and if I sort by time in ascending order, I would expect all values associated with the third index (ie the other dimensions) would be sorted along with it

Code:

t_cat = zeros(240,40,32376);
t = zeros(240,40,32376);
t_cat = cat(3,x,y,z,w);
t = sort(t_cat,3,'ascend');

I feel like I am close and not sure why the above is not working but all I know is that it is not

If any of you can offer some insight, that would be great