annotate scripts/miscellaneous/symvar.m @ 20354:227d582fa300 stable

build: Sort generated PKG_ADD contents consistently * libinterp/mk-pkg-add: Set LC_COLLATE=C when sorting for consistent output.
author Mike Miller <mtmiller@octave.org>
date Fri, 10 Jul 2015 01:10:30 -0400
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19631
diff changeset
1 ## Copyright (C) 2008-2015 David Bateman
7765
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
2 ##
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
3 ## This file is part of Octave.
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
4 ##
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
8 ## your option) any later version.
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
9 ##
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
13 ## General Public License for more details.
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
14 ##
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
18
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
19 ## -*- texinfo -*-
19240
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
20 ## @deftypefn {Function File} {@var{vars} =} symvar (@var{str})
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
21 ## Identify the symbolic variable names in the string @var{str}.
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
22 ##
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
23 ## Common constant names such as @code{i}, @code{j}, @code{pi}, @code{Inf} and
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
24 ## Octave functions such as @code{sin} or @code{plot} are ignored.
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
25 ##
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
26 ## Any names identified are returned in a cell array of strings. The array is
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
27 ## empty if no variables were found.
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
28 ##
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
29 ## Example:
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
30 ##
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
31 ## @example
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
32 ## @group
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
33 ## symvar ("x^2 + y^2 == 4")
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
34 ## @result{} @{
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
35 ## [1,1] = x
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
36 ## [2,1] = y
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
37 ## @}
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
38 ## @end group
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
39 ## @end example
7765
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
40 ## @end deftypefn
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
41
19240
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
42 function vars = symvar (str)
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
43 vars = argnames (inline (str));
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19240
diff changeset
44 ## Correct for auto-generated 'x' variable when no symvar was found.
19240
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
45 if (numel (vars) == 1 && strcmp (vars{1}, "x") && ! any (str == "x"))
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
46 vars = {};
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19240
diff changeset
47 endif
19240
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
48
7765
e800c69ee467 Add symvar function
David Bateman <dbateman@free.fr>
parents:
diff changeset
49 endfunction
12850
979b1a518812 codesprint: Remove symvar from test statistics. Functionality is covered by argnames()
Rik <octave@nomad.inbox5.com>
parents: 12576
diff changeset
50
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
51
19240
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
52 %!assert (symvar ("3*x + 4*y + 5*cos (z)"), {"x"; "y"; "z"})
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
53 %!assert (symvar ("sin()^2 + cos()^2 == 1"), {})
65cf441abc5e symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents: 17744
diff changeset
54 %!assert (symvar ("1./x"), {"x"})
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
55