# MATLAB: Delete a column from an array of uncertain size

drop row; drop column; delete row; delete column

Hi everyone.. I know there are answers out there regarding removing a column from an array with x dimensions–this much I have no problem doing.
I'm trying to turn some code into a function that I can use to solve the same type of problem with anywhere from 2 to 7 dimensions (or infinite, if I can write a general enough code).
What I have to do, in a certain part of the code, is take an array of grid points and drop the first point on the second dimension.
E.g. if it was a matrix I would write:
newarray = oldarray(:,2:end);
if it was a 4D array I would write:
newarray = oldarray(:,2:end,:,:);
What do you think the most efficient/general way to code this would be?
Thanks!

x = 1 + randi(9);   % random no. dimensions from 2 to 10oldarray = rand(repmat(3, 1, x)); % 3 x 3 x 3 ... array
% get cell array of subscript arguments representing whole of oldarraysubs = arrayfun(@(s) {1:s}, size(oldarray));% change second subscript to start from 2subs{2} = 2:size(oldarray,2);% create new array by indexing old arraynewarray = oldarray(subs{:});
disp(size(oldarray));disp(size(newarray));disp(oldarray(1, :, 1, 1, 1, 1, 1, 1, 1, 1, 1));disp(newarray(1, :, 1, 1, 1, 1, 1, 1, 1, 1, 1));