annotate scripts/plot/private/__ezplot__.m @ 14138:72c96de7a403 stable

maint: update copyright notices for 2012
author John W. Eaton <jwe@octave.org>
date Mon, 02 Jan 2012 14:25:41 -0500
parents b0084095098e
children 2fe0f5fa8cc3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11589
diff changeset
1 ## Copyright (C) 2007-2012 David Bateman
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
2 ##
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
4 ##
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
8 ## your option) any later version.
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
9 ##
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
14 ##
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
18
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8046
diff changeset
19 ## -*- texinfo -*-
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8046
diff changeset
20 ## @deftypefn {Function File} {[@var{h}, @var{needusage}] =} __ezplot__ (@var{pfunc}, @var{varargin})
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8046
diff changeset
21 ## Undocumented internal function.
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8046
diff changeset
22 ## @end deftypefn
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
23
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
24 function [h, needusage] = __ezplot__ (pfunc, varargin)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
25
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7337
diff changeset
26 func = cstrcat ("ez", pfunc);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
27 if (strncmp (pfunc, "contour", 7))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
28 iscontour = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
29 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
30 iscontour = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
31 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
32 if (strcmp (pfunc, "plot"))
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
33 isplot = true;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
34 isplot3 = false;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
35 ispolar = false;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
36 nargs = 1;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
37 elseif (strcmp (pfunc, "plot3"))
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
38 isplot = false;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
39 isplot3 = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
40 ispolar = false;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
41 nargs = 1;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
42 elseif (strcmp (pfunc, "polar"))
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
43 isplot = false;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
44 isplot3 = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
45 ispolar = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
46 nargs = 1;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
47 else
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
48 isplot = false;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
49 isplot3 = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
50 ispolar = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
51 nargs = 2;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
52 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
53
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
54 [ax, varargin, nargin] = __plt_get_axis_arg__ (func, varargin{:});
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
55
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
56 needusage = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
57 if (nargin < 1)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
58 needusage = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
59 return;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
60 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
61
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
62 parametric = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
63 fun = varargin {1};
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
64 if (ischar (fun))
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
65 if (exist (fun, "file") || exist (fun, "builtin"))
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
66 fun = vectorize (inline (cstrcat (fun, "(t)")));
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
67 else
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
68 fun = vectorize (inline (fun));
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
69 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
70 if (isplot && length (argnames (fun)) == 2)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
71 nargs = 2;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
72 elseif (length (argnames (fun)) != nargs)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
73 error ("%s: excepting a function of %d arguments", func, nargs);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
74 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
75 fstr = formula (fun);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
76 if (isplot)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
77 xarg = argnames(fun){1};
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
78 if (nargs == 2)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
79 yarg = argnames(fun){2};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
80 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
81 yarg = "";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
82 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
83 elseif (isplot3)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
84 xarg = "x";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
85 yarg = "y";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
86 elseif (ispolar)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
87 xarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
88 yarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
89 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
90 xarg = argnames(fun){1};
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
91 yarg = argnames(fun){2};
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
92 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
93 elseif (strcmp (typeinfo (fun), "inline function"))
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
94 if (isplot && length (argnames (fun)) == 2)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
95 nargs = 2;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
96 elseif (length (argnames (fun)) != nargs)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
97 error ("%s: excepting a function of %d arguments", func, nargs);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
98 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
99 fun = vectorize (fun);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
100 fstr = formula (fun);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
101 if (isplot)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
102 xarg = argnames(fun){1};
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
103 if (nargs == 2)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
104 yarg = argnames(fun){2};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
105 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
106 yarg = "";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
107 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
108 elseif (isplot3)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
109 xarg = "x";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
110 yarg = "y";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
111 elseif (isplot || ispolar)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
112 xarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
113 yarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
114 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
115 xarg = argnames(fun)(1);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
116 yarg = argnames(fun)(2);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
117 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
118 elseif (isa (fun, "function_handle"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
119 fstr = func2str (fun);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
120 if (length (findstr (fstr, ")")) != 0)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
121 args = regexp (substr (fstr, 3, findstr (fstr, ")")(1) - 3),
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
122 '(\w+)', 'tokens');
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
123 fstr = substr (fstr, findstr (fstr, ")")(1) + 1);
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
124 else
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
125 args = {{"x"}};
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
126 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
127 if (isplot && length (args) == 2)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
128 nargs = 2;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
129 elseif (length (args) != nargs)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
130 error ("%s: excepting a function of %d arguments", func, nargs);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
131 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
132 if (isplot)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
133 xarg = args{1}{1};
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
134 if (nargs == 2)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
135 yarg = args{2}{1};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
136 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
137 yarg = "";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
138 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
139 elseif (isplot3)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
140 xarg = "x";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
141 yarg = "y";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
142 elseif (ispolar)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
143 xarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
144 yarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
145 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
146 xarg = args{1}{1};
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
147 yarg = args{2}{1};
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
148 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
149 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
150 error ("%s: expecting string, inline function or function handle", func);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
151 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
152
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
153 if (nargin > 2 || (nargin == 2 && isplot))
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
154 funx = fun;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
155 fstrx = fstr;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
156 funy = varargin {2};
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
157 if (ischar (funy) && ! strcmp (funy, "circ") && ! strcmp (funy, "animate"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
158 parametric = true;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
159 if (exist (funy, "file") || exist (funy, "builtin"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
160 funy = vectorize (inline (cstrcat (funy, "(t)")));
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
161 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
162 funy = vectorize (inline (funy));
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
163 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
164 if (length (argnames (funy)) != nargs)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
165 error ("%s: excepting a function of %d arguments", func, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
166 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
167 fstry = formula (funy);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
168 elseif (strcmp (typeinfo (funy), "inline function"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
169 parametric = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
170 if (length (argnames (funy)) != nargs)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
171 error ("%s: excepting a function of %d arguments", func, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
172 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
173 funy = vectorize (funy);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
174 fstry = formula (funy);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
175 elseif (isa (funy, "function_handle"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
176 parametric = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
177 fstry = func2str (funy);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
178 if (length (findstr (fstry, ")")) != 0)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
179 args = regexp (substr (fstry, 3, findstr (fstry, ")")(1) - 3),
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
180 '(\w+)', 'tokens');
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
181 fstry = substr (fstry, findstr (fstry, ")")(1) + 1);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
182 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
183 args = {{"y"}};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
184 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
185 if (length (args) != nargs)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
186 error ("%s: excepting a function of %d arguments", func, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
187 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
188 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
189
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
190 if (parametric && isplot)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
191 xarg = "x";
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
192 yarg = "y";
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
193 if (nargs == 2)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
194 error ("%s: can not define a parametric function in this manner");
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
195 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
196 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
197
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
198 if (!isplot && parametric)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
199 funz = varargin {3};
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
200 if (ischar (funz) && ! strcmp (funz, "circ")
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
201 && ! strcmp (funz, "animate"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
202 if (exist (funz, "file") || exist (funz, "builtin"))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
203 funz = vectorize (inline (cstrcat (funz, "(t)")));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
204 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
205 funz = vectorize (inline (funz));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
206 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
207 if (length (argnames (funz)) != nargs)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
208 error ("%s: excepting a function of %d arguments", func, nargs);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
209 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
210 fstrz = formula (funz);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
211 elseif (strcmp (typeinfo (funz), "inline function"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
212 if (length (argnames (funz)) != nargs)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
213 error ("%s: excepting a function of %d arguments", func, nargs);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
214 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
215 funz = vectorize (funz);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
216 fstrz = formula (funz);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
217 elseif (isa (funz, "function_handle"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
218 fstrz = func2str (funz);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
219 args = regexp (substr (fstrz, 3, findstr (fstrz, ")")(1) - 3),
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
220 '(\w+)', 'tokens');
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
221 if (length (args) != nargs)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
222 error ("%s: excepting a function of %d arguments", func, nargs);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
223 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
224 fstrz = substr (fstrz, findstr (fstrz, ")")(1) + 1);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
225 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
226 error ("%s: parametric plots expect 3 functions", func);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
227 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
228 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
229 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
230
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
231 if (isplot && nargs != 2)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
232 n = 500;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
233 else
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
234 n = 60;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
235 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
236 domain = [];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
237 circ = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
238 animate = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
239 if (parametric)
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
240 if (isplot)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
241 iarg = 3;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
242 else
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
243 iarg = 4;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
244 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
245 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
246 iarg = 2;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
247 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
248 while (iarg <= nargin)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
249 arg = varargin{iarg++};
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
250 if (ischar (arg) && strcmp (arg, "circ"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
251 circ = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
252 elseif (ischar (arg) && strcmp (arg, "animate"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
253 animate = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
254 elseif (isscalar (arg))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
255 n = arg;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
256 elseif (numel (arg) == 2)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
257 domain = [arg(:).' arg(:).'];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
258 elseif (numel (arg) == 4)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
259 domain = arg(:).';
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
260 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
261 error ("%s: expecting scalar, 2 or 4 element vector", func);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
262 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
263 endwhile
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
264
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
265 if (isempty (domain))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
266 if (isplot3 || ispolar)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
267 domain = [0, 2*pi, 0, 2*pi];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
268 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
269 domain = [-2*pi, 2*pi, -2*pi, 2*pi];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
270 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
271 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
272
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
273 if (circ)
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
274 if (iscontour || isplot3 || isplot)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
275 needusage = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
276 return;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
277 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
278 if (parametric)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
279 error ("%s: can not have both circular domain and parametric function",
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
280 func);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
281 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
282 cent = [domain(1) + domain(2), domain(3) + domain(4)] / 2;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
283 funx = @(r,t) r .* cos (t) + cent (1);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
284 funy = @(r,t) r .* sin (t) + cent (2);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
285 domain = [0, sqrt((domain(2) - cent(1))^2 + (domain(4) - cent(2))^2), ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
286 -pi, pi];
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
287 funz = fun;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
288 parametric = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
289 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
290
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
291 if (animate)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
292 if (!isplot3)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
293 error ("%s: animated graphs only valid with plot3", func);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
294 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
295 error ("%s: animated graphs not implemented", func);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
296 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
297
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
298 if (isplot3 || ispolar || (isplot && nargs == 1))
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
299 X = linspace (domain (1), domain (2), n);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
300 elseif (isplot && numel (domain) == 2)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
301 x = linspace (domain (1), domain (2), n);
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
302 [X, Y] = meshgrid (x, x);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
303 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
304 x = linspace (domain (1), domain (2), n);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
305 y = linspace (domain (3), domain (4), n);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
306 [X, Y] = meshgrid (x, y);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
307 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
308
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
309 if (parametric)
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
310 if (isplot)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
311 XX = feval (funx, X);
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
312 Z = feval (funy, X);
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
313 X = XX;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
314 elseif (isplot3)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
315 Z = feval (funz, X);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
316 XX = feval (funx, X);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
317 YY = feval (funy, X);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
318 X = XX;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
319 Y = YY;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
320 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
321 Z = feval (funz, X, Y);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
322 XX = feval (funx, X, Y);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
323 YY = feval (funy, X, Y);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
324 X = XX;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
325 Y = YY;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
326
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
327 ## Eliminate the singularities
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
328 X = __eliminate_sing__ (X);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
329 Y = __eliminate_sing__ (Y);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
330 Z = __eliminate_sing__ (Z);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
331 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
332
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
333 fstrx = regexprep (regexprep (regexprep (fstrx,'\s*\.?\^\s*','^'),
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
334 '\./', '/'), '\.?\*', '');
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
335 fstry = regexprep (regexprep (regexprep (fstry,'\s*\.?\^\s*','^'),
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
336 '\./', '/'), '\.?\*', '');
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
337 if (isplot)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
338 fstr = cstrcat ("x = ",fstrx,", y = ",fstry);
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
339 else
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
340 fstrz = regexprep (regexprep (regexprep (fstrz,'\s*\.?\^\s*','^'),
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
341 '\./', '/'), '\.?\*', '');
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
342 fstr = cstrcat ("x = ",fstrx,",y = ",fstry,", z = ",fstrz);
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
343 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
344 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
345 if (isplot3)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
346 needusage = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
347 return;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
348 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
349
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
350 fstr = regexprep (regexprep (regexprep (fstr,'\s*\.?\^\s*','^'), '\./', '/'),
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
351 '\.?\*', '');
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
352 if (isplot && nargs == 2)
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
353 if (strcmp (typeinfo (fun), "inline function")
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
354 && !isempty (strfind (formula (fun) , "=")))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
355 fun = inline (cstrcat (strrep (formula (fun), "=", "- ("), ")"));
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
356 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
357 fstr = cstrcat (fstr, " = 0");
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
358 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
359
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
360 Z = feval (fun, X, Y);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
361
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
362 ## Matlab returns line objects for this case and so can't call
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
363 ## contour directly as it returns patch objects to allow colormaps
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
364 ## to work with contours. Therefore recreate the lines from the
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
365 ## output for contourc, and store in cell arrays.
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
366 [c, lev] = contourc (X, Y, Z, [0, 0]);
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
367
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
368 i1 = 1;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
369 XX = {};
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
370 YY = {};
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
371 while (i1 < length (c))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
372 clev = c(1,i1);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
373 clen = c(2,i1);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
374 XX = [XX, {c(1, i1+1:i1+clen)}];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
375 YY = [YY, {c(2, i1+1:i1+clen)}];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
376 i1 += clen+1;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
377 endwhile
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
378 else
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
379 if (ispolar)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
380 Z = feval (fun, X);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
381 elseif (isplot)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
382 Z = real (feval (fun, X));
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
383
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
384 ## Eliminate the singularities. This seems to be what matlab
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
385 ## does, but can't be sure.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
386 XX = sort (Z (isfinite (Z)));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
387 if (length (X) > 4)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
388 d = XX(fix (7 * length (XX) / 8)) - XX(fix (length (XX) / 8));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
389 yrange = [max(XX(1) - d/8, XX(fix (length (XX) / 8)) - d), ...
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
390 min(XX(end) + d/8, XX(fix (7 * length (XX) / 8)) + d)];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
391 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
392 yrange = [XX(1), XX(end)];
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
393 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
394
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
395 idx = 2 : length(Z);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
396 idx = find (((Z(idx) > yrange(2) / 2) & (Z(idx-1) < yrange(1) / 2)) |
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
397 ((Z(idx) < yrange(1) / 2) & (Z(idx-1) > yrange (2) / 2)));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
398 if (any(idx))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
399 Z(idx) = NaN;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
400 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
401 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
402 Z = feval (fun, X, Y);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
403
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
404 ## Eliminate the singularities
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
405 Z = __eliminate_sing__ (Z);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
406 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
407 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
408 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
409
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
410 oldax = gca ();
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
411 unwind_protect
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
412 axes (ax);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
413 if (iscontour)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
414 [clev, h] = feval (pfunc, X, Y, Z);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
415 elseif (isplot && nargs == 2)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
416 h = [];
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
417 hold_state = get (ax, "nextplot");
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
418 for i = 1 : length (XX)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
419 h = [h; plot(XX{i}, YY{i})];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
420 if (i == 1)
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
421 set (ax, "nextplot", "add");
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
422 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
423 endfor
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
424 set (ax, "nextplot", hold_state);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
425 elseif (ispolar || isplot)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
426 h = feval (pfunc, X, Z);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
427 if (isplot && !parametric)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
428 axis ([X(1), X(end), yrange]);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
429 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
430 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
431 h = feval (pfunc, X, Y, Z);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
432 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
433 xlabel (xarg);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
434 ylabel (yarg);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
435 title (fstr);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
436 unwind_protect_cleanup
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
437 axes (oldax);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
438 end_unwind_protect
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
439
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
440 endfunction
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
441
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
442 function x = __eliminate_sing__ (x)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
443 x (isinf (x)) = NaN;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
444 x (abs (del2 (x)) > 0.2 * (max(x(:)) - min(x(:)))) = NaN;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
445 endfunction