comparison scripts/geometry/griddata.m @ 9677:8cf522ce9c4d

fix griddata with vectors
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 01 Oct 2009 08:34:13 +0200
parents 3c40d81c197f
children 479536c5bb10
comparison
equal deleted inserted replaced
9676:e40835382b68 9677:8cf522ce9c4d
49 endif 49 endif
50 if (! all (size (x) == size (y) & size (x) == size (z))) 50 if (! all (size (x) == size (y) & size (x) == size (z)))
51 error ("griddata: x, y, and z must be vectors of same length"); 51 error ("griddata: x, y, and z must be vectors of same length");
52 endif 52 endif
53 53
54 ## Meshgrid xi and yi if they are vectors unless they 54 ## Meshgrid xi and yi if they are a row and column vector.
55 ## are vectors of the same length. 55 if (rows (xi) == 1 && columns (yi) == 1)
56 if (isvector (xi) && isvector (yi) && numel (xi) != numel (yi))
57 [xi, yi] = meshgrid (xi, yi); 56 [xi, yi] = meshgrid (xi, yi);
58 endif 57 endif
59 58
60 if (any (size (xi) != size (yi))) 59 if (! size_equal (xi, yi))
61 error ("griddata: xi and yi must be vectors or matrices of same size"); 60 error ("griddata: xi and yi must be vectors or matrices of same size");
62 endif 61 endif
63 62
64 [nr, nc] = size (xi); 63 [nr, nc] = size (xi);
65 64
112 ## Calculate D of plane equation 111 ## Calculate D of plane equation
113 ## Ax+By+Cz+D = 0; 112 ## Ax+By+Cz+D = 0;
114 D = -(N(:,1) .* x1 + N(:,2) .* y1 + N(:,3) .* z1); 113 D = -(N(:,1) .* x1 + N(:,2) .* y1 + N(:,3) .* z1);
115 114
116 ## Calculate zi by solving plane equation for xi, yi. 115 ## Calculate zi by solving plane equation for xi, yi.
117 zi(valid) = -(N(:,1).*xi(valid) + N(:,2).*yi(valid) + D) ./ N(:,3); 116 zi(valid) = -(N(:,1).*xi(:)(valid) + N(:,2).*yi(:)(valid) + D) ./ N(:,3);
118 117
119 else 118 else
120 error ("griddata: unknown interpolation method"); 119 error ("griddata: unknown interpolation method");
121 endif 120 endif
122 121