There is no operator in MATLAB that does this. However, if your indexes (i.e. bar in your example) were stored in an array , then you can do this:
bar = {3,4,5}; %
{:} creates a comma separated list from an array of cells. This is probably the closest thing you can get in the form of an βoperatorβ that you have in your example, except that it does not overlap one of the existing operators (illustrated here and here ) so that it generates a comma-separated list from a standard array or created your own class to store your indexes and determine how existing operators work (not an option for the faint of heart!).
For your specific example of indexing an arbitrary ND array, you can also calculate a linear index from your indexed indices using sub2ind functions (as described here and here below), but you can end up doing more work than for my comma-separated solution to the list above. Another alternative is to compute the linear index yourself , which will skip the conversion to an array of cells and use only matrix / vector operations. Here is an example:
% Precompute these somewhere: scale = cumprod(size(Q)).'; %' scale = [1; scale(1:end-1)]; shift = [0 ones(1, ndims(Q)-1)]; % Then compute a linear index like this: indices = [3 4 5]; linearIndex = (indices-shift)*scale; Q(linearIndex) % Equivalent to Q(3,4,5)
source share