annotate scripts/plot/draw/private/__ezplot__.m @ 21561:4abcc0969ebd

__ezplot__.m: Remove code deprecated and commented out in v3.8. * __ezplot__.m: Remove code deprecated and commented out in v3.8.
author Rik <rik@octave.org>
date Tue, 29 Mar 2016 21:13:22 -0700
parents 96c768d898f0
children b756cea4fdea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1 ## Copyright (C) 2007-2015 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 -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20711
diff changeset
20 ## @deftypefn {} {[@var{h}, @var{needusage}] =} __ezplot__ (@var{pltfunc}, @var{varargin})
8812
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
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
24 ## Overview: This function is the back-end for the 9 ez* plot functions.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
25 ## As such, most of the function is actually dedicated to sorting
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
26 ## out the inputs and verifying that the particular ez* function
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
27 ## called was called correctly. The actual plotting occurs near
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
28 ## the end in an unwind_protect block.
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
29
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
30 function [h, needusage] = __ezplot__ (pltfunc, varargin)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
31
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
32 ezfunc = ["ez" pltfunc];
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
33
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
34 [hax, varargin, nargin] = __plt_get_axis_arg__ (ezfunc, varargin{:});
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
35
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
36 ## Define outputs early in case of shorting out of function with return;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
37 h = [];
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
38 needusage = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
39 if (nargin < 1)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
40 needusage = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
41 return;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
42 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
43
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
44 iscontour = strncmp (pltfunc, "contour", 7);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
45
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
46 ## Defaults for ezplot
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
47 isplot = true;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
48 isplot3 = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
49 ispolar = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
50 nargs = 1;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
51 switch (pltfunc)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
52 case "plot"
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
53 ## defaults already set
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
54
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
55 case "plot3"
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
56 isplot = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
57 isplot3 = true;
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
58
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
59 case "polar"
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
60 isplot = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
61 ispolar = true;
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
62
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
63 otherwise
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
64 ## contour, mesh, surf plots
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
65 isplot = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
66 nargs = 2;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
67
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
68 endswitch
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
69
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
70 parametric = false;
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
71 fun = varargin{1};
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
72 if (ischar (fun))
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
73 if (exist (fun, "file") || exist (fun, "builtin"))
20499
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
74 fun = str2func (fun); # convert to function handle
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
75 else
20499
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
76 fun = vectorize (inline (fun)); # convert to inline function
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
77 endif
20499
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
78 endif
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
79
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
80 if (strcmp (typeinfo (fun), "inline function"))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
81 argids = argnames (fun);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
82 if (isplot && length (argids) == 2)
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
83 nargs = 2;
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
84 elseif (numel (argids) != nargs)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
85 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
86 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
87 fun = vectorize (fun);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
88 fstr = formula (fun);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
89 if (isplot)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
90 xarg = argids{1};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
91 if (nargs == 2)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
92 yarg = argids{2};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
93 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
94 yarg = "";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
95 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
96 elseif (isplot3)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
97 xarg = "x";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
98 yarg = "y";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
99 elseif (isplot || ispolar)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
100 xarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
101 yarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
102 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
103 xarg = argids{1};
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
104 yarg = argids{2};
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
105 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
106 elseif (isa (fun, "function_handle"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
107 fstr = func2str (fun);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
108 idx = index (fstr, ')');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
109 if (idx != 0)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
110 args = regexp (fstr(3:(idx-1)), '\w+', 'match');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
111 fstr = fstr(idx+2:end); # remove '@(x) ' from string name
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
112 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
113 args = {"x"};
20499
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
114 try
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
115 if (builtin ("nargin", fun) == 2)
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
116 args{2} = "y";
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
117 endif
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
118 end_try_catch
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
119 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
120 if (isplot && length (args) == 2)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
121 nargs = 2;
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
122 elseif (numel (args) != nargs)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
123 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
124 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
125 if (isplot)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
126 xarg = args{1};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
127 if (nargs == 2)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
128 yarg = args{2};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
129 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
130 yarg = "";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
131 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
132 elseif (isplot3)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
133 xarg = "x";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
134 yarg = "y";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
135 elseif (ispolar)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
136 xarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
137 yarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
138 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
139 xarg = args{1};
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
140 yarg = args{2};
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
141 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
142 else
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20499
diff changeset
143 error ("%s: F must be string, inline function, or function handle", ezfunc);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
144 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
145
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
146 if (nargin > 2 || (nargin == 2 && isplot))
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
147 funx = fun;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
148 fstrx = fstr;
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
149 funy = varargin{2};
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
150 if (ischar (funy) && ! strcmp (funy, "circ") && ! strcmp (funy, "animate"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
151 parametric = true;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
152 if (exist (funy, "file") || exist (funy, "builtin"))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
153 funy = inline ([funy "(t)"]);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
154 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
155 funy = vectorize (inline (funy));
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
156 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
157 if (numel (argnames (funy)) != nargs)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
158 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
159 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
160 fstry = formula (funy);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
161 elseif (strcmp (typeinfo (funy), "inline function"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
162 parametric = true;
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
163 if (numel (argnames (funy)) != nargs)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
164 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
165 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
166 funy = vectorize (funy);
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 (isa (funy, "function_handle"))
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 fstry = func2str (funy);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
171 idx = index (fstry, ')');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
172 if (idx != 0)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
173 args = regexp (fstry(3:(idx-1)), '\w+', 'match');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
174 fstry = fstry(idx+2:end); # remove '@(x) ' from string name
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
175 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
176 args = {"y"};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
177 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
178 if (numel (args) != nargs)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
179 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
180 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
181 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
182
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
183 if (! parametric && isplot3)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
184 needusage = true; # Can't call non-parametric ezplot3
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
185 return;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
186 elseif (parametric && isplot)
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
187 if (nargs == 2)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
188 error ("%s: can not define a parametric function in this manner", ezfunc);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
189 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
190 xarg = "x";
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
191 yarg = "y";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
192 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
193 elseif (parametric)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
194 funz = varargin{3};
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
195 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
196 && ! strcmp (funz, "animate"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
197 if (exist (funz, "file") || exist (funz, "builtin"))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
198 funz = inline ([funz "(t)"]);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
199 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
200 funz = vectorize (inline (funz));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
201 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
202 if (numel (argnames (funz)) > nargs)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
203 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
204 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
205 fstrz = formula (funz);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
206 elseif (strcmp (typeinfo (funz), "inline function"))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
207 if (numel (argnames (funz)) != nargs)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
208 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
10549
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 funz = vectorize (funz);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
211 fstrz = formula (funz);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
212 elseif (isa (funz, "function_handle"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
213 fstrz = func2str (funz);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
214 idx = index (fstrz, ')');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
215 if (idx != 0)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
216 args = regexp (fstrz(3:(idx-1)), '\w+', 'match');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
217 fstrz = fstrz(idx+2:end); # remove '@(x) ' from string name
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
218 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
219 args = {"z"};
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
220 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
221 if (numel (args) != nargs)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
222 error ("%s: expecting a function of %d arguments", ezfunc, nargs);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
223 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
224 else
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20499
diff changeset
225 error ("%s: parametric plots require 3 functions", ezfunc);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
226 endif
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
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
230 if ((isplot && nargs != 2) || isplot3 || ispolar)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
231 n = 500; # default for point-style functions like plot
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
232 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
233 n = 60; # default for meshgrid style functions like contour, surf
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
234 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
235 domain = [];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
236 circ = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
237 animate = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
238 if (parametric)
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
239 if (isplot)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
240 iarg = 3;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
241 else
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
242 iarg = 4;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
243 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
244 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
245 iarg = 2;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
246 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
247 while (iarg <= nargin)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
248 arg = varargin{iarg++};
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
249 if (ischar (arg) && strcmp (arg, "circ"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
250 circ = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
251 elseif (ischar (arg) && strcmp (arg, "animate"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
252 animate = true;
21560
96c768d898f0 Use stricter input validation for ezplot N, DOM inputs (bug #46952).
Rik <rik@octave.org>
parents: 21385
diff changeset
253 elseif (isscalar (arg) && (n == 60 || n == 500))
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
254 n = arg;
21560
96c768d898f0 Use stricter input validation for ezplot N, DOM inputs (bug #46952).
Rik <rik@octave.org>
parents: 21385
diff changeset
255 elseif (numel (arg) == 2 && isempty (domain))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
256 domain = [arg(1) arg(2) arg(1) arg(2)];
21560
96c768d898f0 Use stricter input validation for ezplot N, DOM inputs (bug #46952).
Rik <rik@octave.org>
parents: 21385
diff changeset
257 elseif (numel (arg) == 4 && isempty (domain))
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
258 domain = arg(:).';
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
259 else
21560
96c768d898f0 Use stricter input validation for ezplot N, DOM inputs (bug #46952).
Rik <rik@octave.org>
parents: 21385
diff changeset
260 error ("%s: expecting scalar N, or 2-/4-element vector DOM", ezfunc);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
261 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
262 endwhile
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
263
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
264 if (circ && (iscontour || isplot3 || isplot))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
265 needusage = true;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
266 return;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
267 elseif (circ && parametric)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
268 error ("%s: can not have both circular domain and parametric function",
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
269 ezfunc);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
270 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
271
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
272 if (animate && ! isplot3)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
273 error ("%s: animate option only valid for ezplot3", ezfunc);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
274 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
275
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
276 if (parametric)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
277 ## Make the label strings pretty by removing extra spaces between base
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
278 ## and exponent, the '.' in vectorized code, and the '*' for multiply.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
279 fstrx = regexprep (regexprep (regexprep (fstrx,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
280 '\s*\.?(?:\^|\*\*)\s*','^'), '\.([/+-])', '$1'), '\s*\.?\*\s*', ' ');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
281 fstry = regexprep (regexprep (regexprep (fstry,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
282 '\s*\.?(?:\^|\*\*)\s*','^'), '\.([/+-])', '$1'), '\s*\.?\*\s*', ' ');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
283 if (isplot)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
284 fstr = ["x = " fstrx ", y = " fstry];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
285 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
286 fstrz = regexprep (regexprep (regexprep (fstrz,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
287 '\s*\.?(?:\^|\*\*)\s*','^'), '\.([/+-])', '$1'), '\s*\.?\*\s*', ' ');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
288 fstr = ["x = " fstrx ",y = " fstry ", z = " fstrz];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
289 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
290 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
291 fstr = regexprep (regexprep (regexprep (fstr,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
292 '\s*\.?(?:\^|\*\*)\s*','^'), '\.([/+-])', '$1'), '\s*\.?\*\s*', ' ');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
293 if (isplot && nargs == 2)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
294 fstr = [fstr " = 0"]; # make title string of implicit function
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
295 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
296 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
297
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
298 if (isempty (domain))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
299 auto_domain = true;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
300 if (isplot3 || ispolar)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
301 domain = [0, 2*pi, 0, 2*pi];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
302 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
303 domain = [-2*pi, 2*pi, -2*pi, 2*pi];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
304 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
305 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
306 auto_domain = false;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
307 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
308
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
309 auto_domain_done = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
310 do
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
311 domain_ok = true;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
312
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
313 if ((isplot && nargs == 1) || isplot3 || ispolar)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
314 X = linspace (domain(1), domain(2), n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
315 elseif (isplot && numel (domain) == 2)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
316 x = linspace (domain(1), domain(2), n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
317 [X, Y] = meshgrid (x, x);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
318 elseif (circ)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
319 ## To plot on circular domain develop grid in polar coordinates
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
320 ## and then switch these to Cartesian coordinates.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
321 cent = [domain(1) + domain(2), domain(3) + domain(4)] / 2;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
322 rmax = sqrt ((domain(2) - cent(1))^2 + (domain(4) - cent(2))^2);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
323 r = linspace (0, rmax, n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
324 t = linspace (0, 2*pi, n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
325 [T, R] = meshgrid (t, r);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
326 X = R .* cos (T) + cent(1);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
327 Y = R .* sin (T) + cent(2);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
328 domain = [-rmax+cent(1), +rmax+cent(1), -rmax+cent(2), +rmax+cent(2)];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
329 else # contour, mesh, surf plots
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
330 x = linspace (domain(1), domain(2), n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
331 y = linspace (domain(3), domain(4), n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
332 [X, Y] = meshgrid (x, y);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
333 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
334
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
335 if (parametric)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
336 if (isplot)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
337 XX = feval (funx, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
338 Z = feval (funy, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
339 X = XX;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
340 elseif (isplot3)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
341 Z = feval (funz, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
342 XX = feval (funx, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
343 YY = feval (funy, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
344 X = XX;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
345 Y = YY;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
346 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
347 Z = feval (funz, X, Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
348 XX = feval (funx, X, Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
349 YY = feval (funy, X, Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
350 X = XX;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
351 Y = YY;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
352
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
353 ## Eliminate the singularities
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
354 X = __eliminate_sing__ (X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
355 Y = __eliminate_sing__ (Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
356 Z = __eliminate_sing__ (Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
357 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
358 else ## non-parametric plots
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
359 if (isplot && nargs == 2)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
360 Z = feval (fun, X, Y);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
361
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
362 ## Matlab returns line objects for this case and so can't call
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
363 ## contour directly as it returns patch objects to allow colormaps
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
364 ## to work with contours. Therefore recreate the lines from the
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
365 ## output for contourc, and store in cell arrays.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
366 [c, ~] = contourc (X, Y, Z, [0, 0]);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
367
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
368 i = 1;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
369 XX = YY = {};
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
370 while (i < length (c))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
371 clev = c(1,i);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
372 clen = c(2,i);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
373 XX = [XX, {c(1, i+1:i+clen)}];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
374 YY = [YY, {c(2, i+1:i+clen)}];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
375 i += clen+1;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
376 endwhile
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
377 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
378 if (ispolar)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
379 Z = feval (fun, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
380 ## FIXME: Why aren't singularities eliminated for polar plots?
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
381 elseif (isplot)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
382 Z = feval (fun, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
383 ## Eliminate the singularities
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
384 Z = __eliminate_sing__ (Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
385 domain = find_valid_domain (X, [], Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
386 elseif (iscontour)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
387 Z = feval (fun, X, Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
388 Z = __eliminate_sing__ (Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
389 else # mesh, surf plots
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
390 Z = feval (fun, X, Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
391 Z = __eliminate_sing__ (Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
392 if (circ)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
393 ## Use domain calculated at the start.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
394 ## The X, Y grids are non-monotonic after conversion from polar
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
395 ## coordinates and find_valid_domain fails.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
396
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
397 elseif (auto_domain && ! auto_domain_done)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
398 valid_domain = find_valid_domain (X, Y, Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
399 domain_ok = isequal (domain, valid_domain);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
400 domain = valid_domain;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
401 auto_domain_done = true; # ensures only 1 round of do loop done
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
402 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
403 if (! auto_domain_done)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
404 domain = find_valid_domain (X, Y, Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
405 endif
17306
09543e9c8f40 Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents: 17301
diff changeset
406 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
407 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
408 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
409 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
410 until (domain_ok)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
411
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
412 ## Now, actually call the correct plot function with valid data and domain.
17211
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17167
diff changeset
413 oldfig = [];
17301
68bcac3c043a Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents: 17211
diff changeset
414 if (! isempty (hax))
17211
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17167
diff changeset
415 oldfig = get (0, "currentfigure");
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17167
diff changeset
416 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
417 unwind_protect
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
418 hax = newplot (hax);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
419 if (iscontour)
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
420 [~, h] = feval (pltfunc, hax, X, Y, Z);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
421 elseif (isplot && nargs == 2)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
422 h = zeros (length (XX), 1);
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
423 hold_state = get (hax, "nextplot");
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
424 for i = 1 : length (XX)
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
425 h(i) = plot(hax, XX{i}, YY{i});
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
426 if (i == 1)
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
427 set (hax, "nextplot", "add");
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
428 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
429 endfor
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
430 set (hax, "nextplot", hold_state);
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
431 axis (hax, domain);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
432 elseif (isplot || ispolar)
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
433 h = feval (pltfunc, hax, X, Z);
18718
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
434 if (isplot)
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
435 if (! parametric)
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
436 axis (hax, domain);
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
437 else
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
438 axis ("equal");
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
439 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
440 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
441 elseif (isplot3)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
442 if (animate)
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
443 ## draw animation, then replace with true plot3
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
444 comet3 (hax, X, Y, Z, .05);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
445 endif
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
446 h = feval (pltfunc, hax, X, Y, Z);
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
447 set (hax, "box", "off");
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
448 grid (hax, "on");
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
449 zlabel (hax, "z");
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
450 else # mesh and surf plots
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
451 h = feval (pltfunc, hax, X, Y, Z);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
452 ## FIXME: surf, mesh should really do a better job of setting zlim
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
453 if (! parametric)
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
454 axis (hax, domain);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
455 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
456 endif
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
457 xlabel (hax, xarg);
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
458 ylabel (hax, yarg);
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
459 title (hax, fstr);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
460 unwind_protect_cleanup
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
461 if (! isempty (oldfig))
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
462 set (0, "currentfigure", oldfig);
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
463 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
464 end_unwind_protect
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
465
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
466 endfunction
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
467
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
468 ## Eliminate bad data (complex values, infinities, singularities)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
469 function x = __eliminate_sing__ (x)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
470 if (iscomplex (x))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
471 x(imag (x) != 0) = NaN;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
472 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
473 x(isinf (x)) = NaN;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
474 ## High rates of curvature are treated as singularities
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
475 threshold = 0.2 * (max (x(:)) - min (x(:)));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
476 x(abs (del2 (x)) > threshold) = NaN;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
477 endfunction
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
478
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
479 ## Find: 1) range of function where there are not NaN values,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
480 ## 2) function is changing (not just flat surface)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
481 function domain = find_valid_domain (X, Y, Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
482
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
483 if (isvector (Z))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
484 ## 2-D data for isplot
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
485 domain = [X(1) X(end)];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
486
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
487 ## Guess a range which includes the "mass" of the data by using a
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
488 ## median-based approach. The center 3/4 of the data is used to
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
489 ## determine the range of the data.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
490 ## This seems to be vaguely what Matlab does, but can't be sure.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
491 XX = sort (Z(isfinite (Z)));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
492 if (length (X) > 4)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
493 irlo = XX(fix (1/8 * length (XX)));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
494 irhi = XX(fix (7/8 * length (XX)));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
495 d = irhi - irlo;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
496 domain(3) = max (XX(1) - d/8, irlo - d);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
497 domain(4) = min (XX(end) + d/8, irhi + d);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
498 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
499 domain(3:4) = [XX(1), XX(end)];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
500 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
501
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
502 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
503 ## 3-D data such as mesh, surf
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
504 Zfinite = ! isnan (Z);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
505 Zrows = any (Zfinite, 2);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
506 rmin = find (Zrows, 1, "first");
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
507 rmax = find (Zrows, 1, "last");
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
508 Zcols = any (Zfinite, 1);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
509 cmin = find (Zcols, 1, "first");
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
510 cmax = find (Zcols, 1, "last");
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
511
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
512 ## Handle nasty case of all NaNs
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
513 if (isempty (rmin))
21385
89fa0694aa2e Fix check-missing-semicolon QA target (bug #47277).
Rik <rik@octave.org>
parents: 20852
diff changeset
514 rmin = 1; rmax = rows (Z);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
515 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
516 if (isempty (cmin))
21385
89fa0694aa2e Fix check-missing-semicolon QA target (bug #47277).
Rik <rik@octave.org>
parents: 20852
diff changeset
517 cmin = 1; cmax = columns (Z);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
518 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
519
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
520 if ( ! any (isnan (Z([rmin, rmax],:)(:)))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
521 && ! any (isnan (Z(:, [cmin, cmax])(:))))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
522 ## Exclude surfaces along borders which are flat (gradient =~ 0).
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
523 ## Technically, this calculation might be better done with actual
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
524 ## deltaX, deltaY values. But, data is usually meshgridded
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
525 ## (constant spacing) so working with deltaROW#, deltaCOL# is fine.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
526 [Zx, Zy] = gradient (Z(rmin:rmax, cmin:cmax));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
527 Zgrad = sqrt (Zx.^2 + Zy.^2);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
528 slope = ((max (Z(:)) - min (Z(:)))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
529 / sqrt ((rmax - rmin)^2 + (cmax - cmin)^2));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
530 slope /= 125; # threshold for discarding points.
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
531 Zrows = any (Zgrad > slope, 2);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
532 rmin += find (Zrows, 1, "first") - 1;
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
533 rmax += find (Zrows, 1, "last") - rows (Zrows);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
534 Zcols = any (Zgrad > slope, 1);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
535 cmin += find (Zcols, 1, "first") - 1;
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
536 cmax += find (Zcols, 1, "last") - columns (Zcols);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
537 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
538
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
539 domain = [X(1,cmin) X(1,cmax) Y(rmin,1) Y(rmax,1)];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
540 endif
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
541
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
542 endfunction
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
543