Mercurial > hg > octave-nkf
annotate scripts/miscellaneous/symvar.m @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19794
diff
changeset
|
1 ## Copyright (C) 2008-2015 David Bateman |
7765 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
19398
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 | 40 ## @end deftypefn |
41 | |
19398
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)); |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19398
diff
changeset
|
44 ## Correct for auto-generated 'x' variable when no symvar was found. |
19398
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 = {}; |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19398
diff
changeset
|
47 endif |
19398
65cf441abc5e
symvar.m: Correct the return value when no arguments were found.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
48 |
7765 | 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 |
19398
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 |