Mercurial > hg > ishara
annotate general/arrutils/sli.m @ 4:e44f49929e56
Adding reorganised general toolbox, now in several subdirectories.
author | samer |
---|---|
date | Sat, 12 Jan 2013 19:21:22 +0000 |
parents | |
children |
rev | line source |
---|---|
samer@4 | 1 function y=sli(x,i,dim) |
samer@4 | 2 % sli - Take a slice of a multidimensional array |
samer@4 | 3 % |
samer@4 | 4 % sli :: |
samer@4 | 5 % [Size:[[E]]->A] ~'E dimensional array of size Size, element type A', |
samer@4 | 6 % [[M]->1..Size(Dim)] ~'vector of M indices in Dim'th dimension', |
samer@4 | 7 % Dim:1..E ~'dimension to act along' |
samer@4 | 8 % -> [Size2:[[E]]->A] ~'new array of size Size2 :- |
samer@4 | 9 % Size2=set(Size,Dim,M) ~'new size same as old but with Dim'th entry replaced with M'. |
samer@4 | 10 |
samer@4 | 11 n=ndims(x); |
samer@4 | 12 idx=repmat({':'},1,n); |
samer@4 | 13 idx{dim}=i; |
samer@4 | 14 y=x(idx{:}); |
samer@4 | 15 |