function zi = sliceg(x, y, z, xi, yi, method) % sliceg -- Interpolation along a non-monotonic track. % sliceg('demo') demonstrates itself. % sliceg(N) demonstrates itself with an N-by-N surface % and N points along a random track. (default = 10). % sliceg(x, y, xi, yi, 'method') uses the syntax of % "interp2" to interpolate the (x, y, z) grid along % a (possibly) non-monotonic (xi, yi) track. The % track points must be unique. % % Also see: "help interp2". % Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 20-Jan-2000 12:17:03. % Updated 20-Jan-2000 21:13:47. if nargin < 1, x = 'demo'; help(mfilename), end if isequal(x, 'demo'), x = 10; end if ischar(x), x = eval(x); end if length(x) < 2 n = x; i = linspace(0, 1, n+1); [x, y] = meshgrid(i, i); z = x + y; xi = sort(rand(1, n)); yi = rand(size(xi)); result = feval(mfilename, x, y, z, xi, yi); surf(x, y, z); hold on plot3(xi, yi, 0*result-1, '-g', 'LineWidth', 3); plot3(xi, yi, 0*result+3, '-g', 'LineWidth', 3); plot3([xi;xi], [yi; yi], [0*result-1; 0*result+3], '-ko') plot3(xi, yi, result+0.01, '-k', 'LineWidth', 3); hold off box on shading faceted rotate3d figure(gcf) s = [mfilename ' ' int2str(n)]; set(gcf, 'Name', s) return end % Sort the data and remember original indices. % We assume that there are no points identical. [yi, i] = sort(yi); xi = xi(i); [xi, j] = sort(xi); yi = yi(j); i = i(j); if nargin < 6 zi = interp2(x, y, z, xi, yi); else zi = interp2(x, y, z, xi, yi, method); end zi(i) = zi;