changeset 7423:342a48abed2a

[project @ 2008-01-25 23:54:47 by dbateman]
author dbateman
date Fri, 25 Jan 2008 23:54:47 +0000
parents a7554a7f9981
children 132647e6c829
files scripts/ChangeLog scripts/general/__splinen__.m scripts/general/interpn.m
diffstat 3 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Jan 25 22:54:33 2008 +0000
+++ b/scripts/ChangeLog	Fri Jan 25 23:54:47 2008 +0000
@@ -5,6 +5,7 @@
 	
 2008-01-25  David Bateman  <dbateman@free.fr>
 
+	* general/__splinen__.m: Treat mixed orientation vectors.
 	* plot/__scatter__.m: Remove NaN values from data.
 	* plot/__patch__.m: Vectorize treatment of trailing NaN values.
 
--- a/scripts/general/__splinen__.m	Fri Jan 25 22:54:33 2008 +0000
+++ b/scripts/general/__splinen__.m	Fri Jan 25 23:54:47 2008 +0000
@@ -39,7 +39,7 @@
     yi = permute (spline (x{i}, yi, xi{i}), [length(x),1:length(x)-1]);
   endfor
 
-  [xi{:}] = ndgrid (xi{:});
+  [xi{:}] = ndgrid (cellfun (@(x) x(:), xi, "UniformOutput", false){:});
   idx = zeros (size(xi{1}));
   for i = 1 : length(x)
     idx |= xi{i} < min (x{i}(:)) | xi{i} > max (x{i}(:));
--- a/scripts/general/interpn.m	Fri Jan 25 22:54:33 2008 +0000
+++ b/scripts/general/interpn.m	Fri Jan 25 23:54:47 2008 +0000
@@ -158,17 +158,33 @@
     vi(idx) = extrapval;
     vi = reshape (vi, yshape); 
   elseif (strcmp (method, "spline"))
-    szi = size (y{1});
-    for i = 1 : nd
-      y{i} = y{i}(:);
-    endfor
+    if (any (! cellfun (@isvector, y)))
+      for i = 2 : nd
+	if (! size_equal (y{1}, y{i}))
+	  error ("dimensional mismatch");
+	endif
+	idx (1 : nd) = {1};
+	idx (i) = ":";
+	y{i} = y{i}(idx{:});
+      endfor
+      idx (1 : nd) = {1};
+      idx (1) = ":";
+      y{1} = y{1}(idx{:});
+    endif
 
     vi = __splinen__ (x, v, y, extrapval, "interpn");
 
-    ## get all diagonal elements of vi
-    sc = sum ([1 cumprod(size (vi)(1:end-1))]);
-    vi = vi(sc * [0:size(vi,1)-1] + 1);
-    vi = reshape (vi,szi);    
+    if (size_equal (y{:}))
+      ly = length (y{1});
+      idx = cell (1, ly);
+      q = cell (1, nd);
+      for i = 1 : ly
+ 	q(:) = i;
+ 	idx {i} = q;
+      endfor
+      vi = vi (cellfun (@(x) sub2ind (size(vi), x{:}), idx));
+      vi = reshape (vi, sz);    
+    endif
   elseif (strcmp (method, "cubic")) 
     error ("cubic interpolation not yet implemented");
   else