diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/general/arrutils/sli.m	Sat Jan 12 19:21:22 2013 +0000
@@ -0,0 +1,15 @@
+function y=sli(x,i,dim)
+% sli - Take a slice of a multidimensional array
+%
+% sli :: 
+%    [Size:[[E]]->A]     ~'E dimensional array of size Size, element type A', 
+%    [[M]->1..Size(Dim)] ~'vector of M indices in Dim'th dimension',
+%    Dim:1..E            ~'dimension to act along'
+% -> [Size2:[[E]]->A]    ~'new array of size Size2 :-
+%    Size2=set(Size,Dim,M) ~'new size same as old but with Dim'th entry replaced with M'.
+
+	n=ndims(x);
+	idx=repmat({':'},1,n);
+	idx{dim}=i;
+	y=x(idx{:});
+