I need to develop a function that can accept any n-dimensional arrays. It should access cells of the arrays in the following way:
mat(1:end-1, :, :, ... :);mat( :, 1:end-1, :, ... :);mat( :, :, 1:end-1, ... :);mat( :, :, :, ... 1:end-1);
And also by other similar combinations for more then one dimension, e.g.:
mat(1:end-1, :, 1:end-1, ... :);
How can it be done in a smarter way, so I do not need to consider all cases manually, and it can be universal for any number of dimensions?
I was looking for something as:
new_mat = function(mat, (vector with dimensions to be used), (vectors used to access cells, e.g., 1:end-1));
For example it could be:
new_mat = function(mat, [1 3], [1:end-1; 2:end]);
which is equivalent to:
new_mat = mat(1:end-1, :, 1:end-1, ... :);
GREAT THANKS!
Best Answer