access a specified dimension of a N-D array

88 views Asked by At

I have a 3D array in MATLAB, with

size(myArray) = [1400 720 120]

the third dimension is 120 levels of depths : 0 - 5 - 10 .., and the 1400 and 720 is a geographic grid with values for each level of depth. I would like to get a specific layer, specified by an index in the third dimension (example depth = 5), in the form of a 2D matrix.

The squeeze function doesn't access the a specific number of the third dimension and my 2D matrix looks like:

B=squeeze(A(:,:,3));
size(B)
[1440 720]

How can I access the layer i.e: 5m of the [1440 720] matrix?

1

There are 1 answers

1
Kostya On BEST ANSWER

It looks like you are looking for something like this

zscale = 5;

depth = 5;
B = A(:,:,depth/zscale);