home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / SPLINE2D.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.6 KB  |  68 lines

  1. %SPLINE2D Demonstrate GINPUT and SPLINE in two dimensions.
  2.  
  3. %   CBM, 8-9-91, 8-12-92.
  4. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  5.  
  6. clf
  7. axis([0 10 0 10])
  8. hold on
  9. view(0,90)
  10. clc
  11. echo on
  12.  
  13. % This demonstration illustrates the use of the GINPUT function,
  14. % which obtains graphic positional input via a mouse or cursor,
  15. % and the SPLINE function, which interpolates data with a cubic spline.  
  16. % The demonstration does NOT use the Spline Toolbox, which is a
  17. % complete set of functions for B-splines and other piecewise polynomials
  18. % of any degree.
  19. %
  20. % Press any key to continue after pauses.
  21. pause
  22.  
  23. clc
  24.  
  25. % Here is code which uses the left mouse button to pick a sequence of
  26. % points and the right mouse button to pick the last point.
  27. % Initially, the list of points is empty and its length is 0.
  28.  
  29. % Please use the left mouse button or the cursor to select several points;
  30. % use the right mouse button to select the final point.
  31.  
  32. x = [];
  33. y = [];
  34. n = 0;
  35. % Loop, picking up the points.
  36. but = 1;
  37. while but == 1
  38.    [xi,yi,but] = ginput(1);
  39.    plot(xi,yi,'go','era','back') % doesn't matter what erase mode is
  40.                 % used so long as its not NORMAL
  41.    n = n + 1;
  42.    text(xi,yi,[' ' int2str(n)],'era','back');
  43.    x = [x; xi];
  44.    y = [y; yi];
  45. end
  46. disp('End of data entry')
  47.  
  48. pause
  49.  
  50. clc
  51.  
  52. % Interpolate the points with two splines, evaluated with a finer spacing.
  53.  
  54. t = 1:n;
  55. ts = 1:1/10:n;
  56. xs = spline(t,x,ts);
  57. ys = spline(t,y,ts);
  58.  
  59. pause
  60.  
  61. % Plot the interpolated curve with a cyan colored line.
  62.  
  63. plot(xs,ys,'c-');
  64.  
  65. echo off
  66. hold off
  67. disp('End')
  68.