/usr/share/doc/octave/octave.html/Variables.html is in octave-doc 4.2.2-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Variables (GNU Octave)</title>
<meta name="description" content="Variables (GNU Octave)">
<meta name="keywords" content="Variables (GNU Octave)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Global-Variables.html#Global-Variables" rel="next" title="Global Variables">
<link href="Comma-Separated-Lists-Generated-from-Structure-Arrays.html#Comma-Separated-Lists-Generated-from-Structure-Arrays" rel="prev" title="Comma Separated Lists Generated from Structure Arrays">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<a name="Variables"></a>
<div class="header">
<p>
Next: <a href="Expressions.html#Expressions" accesskey="n" rel="next">Expressions</a>, Previous: <a href="Data-Containers.html#Data-Containers" accesskey="p" rel="prev">Data Containers</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Variables-1"></a>
<h2 class="chapter">7 Variables</h2>
<a name="index-variables_002c-user_002ddefined"></a>
<a name="index-user_002ddefined-variables"></a>
<p>Variables let you give names to values and refer to them later. You have
already seen variables in many of the examples. The name of a variable
must be a sequence of letters, digits and underscores, but it may not begin
with a digit. Octave does not enforce a limit on the length of variable
names, but it is seldom useful to have variables with names longer than
about 30 characters. The following are all valid variable names
</p>
<div class="example">
<pre class="example">x
x15
__foo_bar_baz__
fucnrdthsucngtagdjb
</pre></div>
<p>However, names like <code>__foo_bar_baz__</code> that begin and end with two
underscores are understood to be reserved for internal use by Octave.
You should not use them in code you write, except to access Octave’s
documented internal variables and built-in symbolic constants.
</p>
<p>Case is significant in variable names. The symbols <code>a</code> and
<code>A</code> are distinct variables.
</p>
<p>A variable name is a valid expression by itself. It represents the
variable’s current value. Variables are given new values with
<em>assignment operators</em> and <em>increment operators</em>.
See <a href="Assignment-Ops.html#Assignment-Ops">Assignment Expressions</a>.
</p>
<p>There is one built-in variable with a special meaning. The <code>ans</code> variable
always contains the result of the last computation, where the output wasn’t
assigned to any variable. The code <code>a = cos (pi)</code> will assign the value
-1 to the variable <code>a</code>, but will not change the value of <code>ans</code>.
However, the code <code>cos (pi)</code> will set the value of <code>ans</code> to -1.
</p>
<p>Variables in Octave do not have fixed types, so it is possible to first
store a numeric value in a variable and then to later use the same name
to hold a string value in the same program. Variables may not be used
before they have been given a value. Doing so results in an error.
</p>
<a name="index-ans"></a>
<a name="XREFans"></a><dl>
<dt><a name="index-ans-1"></a>Automatic Variable: <strong>ans</strong></dt>
<dd><p>The most recently computed result that was not explicitly assigned to a
variable.
</p>
<p>For example, after the expression
</p>
<div class="example">
<pre class="example">3^2 + 4^2
</pre></div>
<p>is evaluated, the value returned by <code>ans</code> is 25.
</p></dd></dl>
<a name="XREFisvarname"></a><dl>
<dt><a name="index-isvarname"></a>: <em></em> <strong>isvarname</strong> <em>(<var>name</var>)</em></dt>
<dd><p>Return true if <var>name</var> is a valid variable name.
</p>
<p><strong>See also:</strong> <a href="Keywords.html#XREFiskeyword">iskeyword</a>, <a href="Status-of-Variables.html#XREFexist">exist</a>, <a href="Status-of-Variables.html#XREFwho">who</a>.
</p></dd></dl>
<a name="XREFgenvarname"></a><dl>
<dt><a name="index-genvarname"></a>: <em><var>varname</var> =</em> <strong>genvarname</strong> <em>(<var>str</var>)</em></dt>
<dt><a name="index-genvarname-1"></a>: <em><var>varname</var> =</em> <strong>genvarname</strong> <em>(<var>str</var>, <var>exclusions</var>)</em></dt>
<dd><p>Create valid unique variable name(s) from <var>str</var>.
</p>
<p>If <var>str</var> is a cellstr, then a unique variable is created for each cell
in <var>str</var>.
</p>
<div class="example">
<pre class="example">genvarname ({"foo", "foo"})
⇒
{
[1,1] = foo
[1,2] = foo1
}
</pre></div>
<p>If <var>exclusions</var> is given, then the variable(s) will be unique to each
other and to <var>exclusions</var> (<var>exclusions</var> may be either a string or a
cellstr).
</p>
<div class="example">
<pre class="example">x = 3.141;
genvarname ("x", who ())
⇒ x1
</pre></div>
<p>Note that the result is a char array or cell array of strings, not the
variables themselves. To define a variable, <code>eval()</code> can be used.
The following trivial example sets <code>x</code> to <code>42</code>.
</p>
<div class="example">
<pre class="example">name = genvarname ("x");
eval ([name " = 42"]);
⇒ x = 42
</pre></div>
<p>This can be useful for creating unique struct field names.
</p>
<div class="example">
<pre class="example">x = struct ();
for i = 1:3
x.(genvarname ("a", fieldnames (x))) = i;
endfor
⇒ x =
{
a = 1
a1 = 2
a2 = 3
}
</pre></div>
<p>Since variable names may only contain letters, digits, and underscores,
<code>genvarname</code> will replace any sequence of disallowed characters with
an underscore. Also, variables may not begin with a digit; in this case
an ‘<samp>x</samp>’ is added before the variable name.
</p>
<p>Variable names beginning and ending with two underscores <code>"__"</code> are
valid, but they are used internally by Octave and should generally be
avoided; therefore, <code>genvarname</code> will not generate such names.
</p>
<p><code>genvarname</code> will also ensure that returned names do not clash with
keywords such as <code>"for"</code> and <code>"if"</code>. A number will be
appended if necessary. Note, however, that this does <strong>not</strong> include
function names such as <code>"sin"</code>. Such names should be included in
<var>exclusions</var> if necessary.
</p>
<p><strong>See also:</strong> <a href="#XREFisvarname">isvarname</a>, <a href="Keywords.html#XREFiskeyword">iskeyword</a>, <a href="Status-of-Variables.html#XREFexist">exist</a>, <a href="Status-of-Variables.html#XREFwho">who</a>, <a href="Temporary-Files.html#XREFtempname">tempname</a>, <a href="Evaluation.html#XREFeval">eval</a>.
</p></dd></dl>
<a name="XREFnamelengthmax"></a><dl>
<dt><a name="index-namelengthmax"></a>: <em></em> <strong>namelengthmax</strong> <em>()</em></dt>
<dd><p>Return the <small>MATLAB</small> compatible maximum variable name length.
</p>
<p>Octave is capable of storing strings up to <em>2^{31} - 1</em> in length.
However for <small>MATLAB</small> compatibility all variable, function, and structure
field names should be shorter than the length returned by
<code>namelengthmax</code>. In particular, variables stored to a <small>MATLAB</small> file
format (<samp>*.mat</samp>) will have their names truncated to this length.
</p></dd></dl>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="Global-Variables.html#Global-Variables" accesskey="1">Global Variables</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Persistent-Variables.html#Persistent-Variables" accesskey="2">Persistent Variables</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Status-of-Variables.html#Status-of-Variables" accesskey="3">Status of Variables</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<div class="header">
<p>
Next: <a href="Expressions.html#Expressions" accesskey="n" rel="next">Expressions</a>, Previous: <a href="Data-Containers.html#Data-Containers" accesskey="p" rel="prev">Data Containers</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|