Equivalent for (:) for slices of higher dimension matrices

Viewed 53

Context

You have a 3D variable A

rng('default')
A = randi(100,5,7,3);

Problem

You want to get a column vector with all the values of a given slice along the third dimension of A, e.g.

Tmp = A(:,:,2);
out = Tmp(:);

Question

Is there a built in way to do this directly without having to use a temporary variable or a function (i.e. with a combination of brackets, ...)? The closest to what I look for I have found yet would be

out = reshape(A(:,:,2),[],1)

Which I find a bit "heavy". I was looking for something like (A(:,:,2))(:) but it doesn't work in MATLAB.

The fact that they added the input all in functions like any would suggest that there is not but I figured I'd still ask

0 Answers
Related