]> Creatis software - CreaPhase.git/blob - octave_packages/splines-1.0.7/fnplt.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / splines-1.0.7 / fnplt.m
1 ## Copyright (C) 2000  Kai Habel
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} { } fnplt (@var{pp}, '@var{plt}')
18 ## plots spline 
19 ##
20 ## @seealso{ppval, spline, csape}
21 ## @end deftypefn
22
23 ## Author:  Kai Habel <kai.habel@gmx.de>
24 ## Date: 3. dec 2000
25 ## 2001-02-19 Paul Kienzle
26 ##   * use pp.x rather than just x in linspace; add plt parameter
27 ##   * return points instead of plotting them if desired
28 ##   * also plot control points
29 ##   * added demo
30
31 function [x, y] = fnplt (pp, plt)
32
33   if (nargin < 1 || nargin > 2)
34     usage ("[x, y] = fnplt (pp [, plotstring])");
35   endif
36   if (nargin < 2)
37     plt = "r;;";
38   endif
39   xi = linspace(min(pp.x),max(pp.x),256)';
40   pts = ppval(pp,xi);
41   if nargout == 2
42     x = xi;
43     y = pts;
44   elseif nargout == 1
45     x = [xi, pts];
46   else
47     plot(xi,pts,plt,pp.x,ppval(pp,pp.x),"bx;;");
48   endif
49
50 endfunction
51
52 %!demo
53 %! x = [ 0; sort(rand(25,1)); 1 ];
54 %! pp = csape (x, sin (2*pi*3*x), 'periodic');
55 %! axis([0,1,-2,2]); 
56 %! title('Periodic spline reconstruction of randomly sampled sine');
57 %! fnplt (pp,'r;reconstruction;'); 
58 %! t=linspace(0,1,100); y=sin(2*pi*3*t);
59 %! hold on; plot(t,y,'g;ideal;'); hold off;
60 %! axis; title("");