comparison scripts/geometry/griddata.m @ 20214:561af1ab6099

griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125) * griddata.m: Return interpolated values instead of plotting a mesh for compatibility with Matlab. Adjust %!demos to call mesh on the output. * NEWS: Mention change to griddata for 4.2.
author Mike Miller <mtmiller@octave.org>
date Thu, 21 May 2015 22:35:51 -0400
parents 7503499a252b
children 516bb87ea72e
comparison
equal deleted inserted replaced
20211:f2bc7d23295d 20214:561af1ab6099
131 131
132 else 132 else
133 error ("griddata: unknown interpolation METHOD"); 133 error ("griddata: unknown interpolation METHOD");
134 endif 134 endif
135 135
136 if (nargout == 3) 136 if (nargout > 1)
137 rx = xi; 137 rx = xi;
138 ry = yi; 138 ry = yi;
139 rz = zi; 139 rz = zi;
140 elseif (nargout == 1) 140 else
141 rx = zi; 141 rx = zi;
142 elseif (nargout == 0)
143 mesh (xi, yi, zi);
144 endif 142 endif
145 143
146 endfunction 144 endfunction
147 145
148 146
151 %! colormap ("default"); 149 %! colormap ("default");
152 %! x = 2*rand (100,1) - 1; 150 %! x = 2*rand (100,1) - 1;
153 %! y = 2*rand (size (x)) - 1; 151 %! y = 2*rand (size (x)) - 1;
154 %! z = sin (2*(x.^2 + y.^2)); 152 %! z = sin (2*(x.^2 + y.^2));
155 %! [xx,yy] = meshgrid (linspace (-1,1,32)); 153 %! [xx,yy] = meshgrid (linspace (-1,1,32));
156 %! griddata (x,y,z,xx,yy); 154 %! zz = griddata (x,y,z,xx,yy);
155 %! mesh (xx, yy, zz);
157 %! title ("nonuniform grid sampled at 100 points"); 156 %! title ("nonuniform grid sampled at 100 points");
158 157
159 %!demo 158 %!demo
160 %! clf; 159 %! clf;
161 %! colormap ("default"); 160 %! colormap ("default");
162 %! x = 2*rand (1000,1) - 1; 161 %! x = 2*rand (1000,1) - 1;
163 %! y = 2*rand (size (x)) - 1; 162 %! y = 2*rand (size (x)) - 1;
164 %! z = sin (2*(x.^2 + y.^2)); 163 %! z = sin (2*(x.^2 + y.^2));
165 %! [xx,yy] = meshgrid (linspace (-1,1,32)); 164 %! [xx,yy] = meshgrid (linspace (-1,1,32));
166 %! griddata (x,y,z,xx,yy); 165 %! zz = griddata (x,y,z,xx,yy);
166 %! mesh (xx, yy, zz);
167 %! title ("nonuniform grid sampled at 1000 points"); 167 %! title ("nonuniform grid sampled at 1000 points");
168 168
169 %!demo 169 %!demo
170 %! clf; 170 %! clf;
171 %! colormap ("default"); 171 %! colormap ("default");
172 %! x = 2*rand (1000,1) - 1; 172 %! x = 2*rand (1000,1) - 1;
173 %! y = 2*rand (size (x)) - 1; 173 %! y = 2*rand (size (x)) - 1;
174 %! z = sin (2*(x.^2 + y.^2)); 174 %! z = sin (2*(x.^2 + y.^2));
175 %! [xx,yy] = meshgrid (linspace (-1,1,32)); 175 %! [xx,yy] = meshgrid (linspace (-1,1,32));
176 %! griddata (x,y,z,xx,yy,"nearest"); 176 %! zz = griddata (x,y,z,xx,yy,"nearest");
177 %! mesh (xx, yy, zz);
177 %! title ("nonuniform grid sampled at 1000 points with nearest neighbor"); 178 %! title ("nonuniform grid sampled at 1000 points with nearest neighbor");
178 179
179 %!testif HAVE_QHULL 180 %!testif HAVE_QHULL
180 %! [xx,yy] = meshgrid (linspace (-1,1,32)); 181 %! [xx,yy] = meshgrid (linspace (-1,1,32));
181 %! x = xx(:); 182 %! x = xx(:);