% EXTRACT - Extract a sub-array
%
% extract :: 
%	[[size:[E]]], 
%	n:1..E, 
%	[[2]->natural]~'start and end indices' 
% -> [[size1:[E]].
%
% Examples (assuming A is 3D): 
%	extract(A,2,[4 20]) = A(:,4:20,:)
%	extract(A,3,[2 10]) = A(:,:,2:10)
function y=extract(x,dim,range)

	persistent colons

	n=ndims(x);
	if length(colons)<n,
		colons=repmat({':'},1,n);
	end

	s=colons(1:n); %cell(1,n); s(:)={':'};
	s{dim}=range(1):range(2);
	S.type='()';
	S.subs=s;
	y=subsref(x,S);
