You can use shiftdim to move the last dimension to the first and index it and change it back.
x = rand(2,3,4,5,6); sz = size(x); A = shiftdim(x, numel(sz)-1); B = reshape(A(1,:), sz(1:end-1));
and
>> isequal(B, x(:,:,:,:,1)) ans = 1
or you can use subsref to index it:
B = subsref(x, substruct('()', [num2cell(repmat(':', 1, ndims(x)-1)) 1]))
source share