No BSD License  

Highlights from
submat_noeval

from submat_noeval by Garrett Euler
Returns the input matrix reduced along indicated dimensions (without eval)

[X]=submat_noeval(X,varargin)
function [X]=submat_noeval(X,varargin)
%SUBMAT_NOEVAL    Returns a submatrix reduced along indicated dimensions
%
%    Description: Y=SUBMAT_NOEVAL(X,DIM,LIST) creates a matrix Y that is
%     the matrix X reduced along dimension DIM to the indices in LIST.  If
%     DIM is a list of dimensions, LIST is used to reduce each dimension.
%
%     Y=SUBMAT_NOEVAL(X,DIM1,LIST1,DIM2,LIST2,...) allows for access to
%     multiple dimensions independently.
%
%    Usage: Y=submat_noeval(X,DIM1,LIST1,DIM2,LIST2,...)
%
%    Examples:
%      Return x reduced to only the elements in index 1 of dimension 5:
%      x=submat_noeval(x,5,1)
%
%    See also: colon operator (:), repmat

% CHECK VARARGIN
if(~mod(nargin,2))
    error('dimension argument must be followed by indices argument');
end

% DEFAULT TO ENTIRE MATRIX AND EXPAND TO MAX INPUT DIMENSION
list(1:max([ndims(X) [varargin{1:2:end}]]))={':'};

% REDUCED/REPLICATED DIMENSIONS
for i=1:2:nargin-2
    [list{[varargin{i}]}]=deal(varargin{i+1});
end

% SUBSET
X=X(list{:});

end

Contact us at files@mathworks.com