Mercurial > hg > ishara
diff general/arrutils/extract.m @ 4:e44f49929e56
Adding reorganised general toolbox, now in several subdirectories.
author | samer |
---|---|
date | Sat, 12 Jan 2013 19:21:22 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/general/arrutils/extract.m Sat Jan 12 19:21:22 2013 +0000 @@ -0,0 +1,25 @@ +% 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);