I have a variable dimension matrix, X. I want a function that will get the first half of X in one dimension. I.E., I want something like this:
function x = variableSubmatrix(x, d)
if d == 1
switch ndims(x)
case 1
x = x(1:end/2);
case 2
x = x(1:end/2, :);
case 3
x = x(1:end/2, :, :);
(...)
end
elseif d == 2
switch ndims(x)
case 2
x = x(:, 1:end/2);
case 3
x = x(:, 1:end/2, :);
(...)
end
elseif (...)
end
end
I'm not quite sure how to do this. I need it to be fast, as this will be used many times in computation.