0001 function needlePlot(data)
0002
0003
0004
0005
0006
0007
0008
0009 if nargin == 0, selfdemo; return, end
0010
0011 x = data(:, 1);
0012 y = data(:, 2);
0013 z = data(:, 3);
0014 figure
0015 plot3(x, y, z, 'o');
0016 bottom = min(z);
0017 data_n = length(x);
0018 for i = 1:data_n,
0019 line([x(i) x(i)], [y(i), y(i)], [bottom, z(i)], 'color', 'c');
0020 end
0021 axis([-inf inf -inf inf -inf inf]);
0022 xlabel('X'); ylabel('Y'); zlabel('Z');
0023 title('Needle plot for data points');
0024 set(gca, 'box', 'on');
0025
0026 rotate3d on
0027 hold on
0028 plot(x, y);
0029 hold off
0030
0031
0032 figure;
0033 point_n = 21;
0034 xi = linspace(min(x), max(x), point_n);
0035 yi = linspace(min(y), max(y), point_n);
0036 [xx, yy] = meshgrid(xi, yi);
0037 [xx, yy, zz] = griddata(x, y, z, xx, yy);
0038 mesh(xx, yy, zz);
0039 hold on
0040 plot3(x, y, z, 'o');
0041 hold off
0042 xlabel('X'); ylabel('Y'); zlabel('Z');
0043 title('Data points and 2D interpolation');
0044 set(gca, 'box', 'on');
0045 axis([-inf inf -inf inf -inf inf]);
0046
0047 rotate3d on
0048
0049
0050 figure;
0051
0052 contour(xx, yy, zz, 10);
0053 hold on
0054 line(x, y, 'linestyle', 'o');
0055 hold off
0056 xlabel('X'); ylabel('Y');
0057 title('Data points and contours for 2D interpolation');
0058 axis image
0059
0060 function selfdemo
0061 t = linspace(0, 5*pi)';
0062 x = t.*sin(t);
0063 y = t.*cos(t);
0064 z = t;
0065 feval(mfilename, [x y z]);