Mercurial > octave-nkf
annotate doc/interpreter/func.txi @ 10209:ea0d83b4470b
document use of ~ placeholders in the manual
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 27 Jan 2010 13:47:02 +0100 |
parents | 923c7cb7f13f |
children | fbd7843974fa |
rev | line source |
---|---|
8920 | 1 @c Copyright (C) 1996, 1997, 2007, 2008, 2009 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Functions and Scripts |
9032
349616d9c38e
Cleanup top-level documentation menu in octave.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
20 @chapter Functions and Scripts |
3294 | 21 @cindex defining functions |
22 @cindex user-defined functions | |
23 @cindex functions, user-defined | |
24 @cindex script files | |
25 | |
26 Complicated Octave programs can often be simplified by defining | |
27 functions. Functions can be defined directly on the command line during | |
28 interactive Octave sessions, or in external files, and can be called just | |
29 like built-in functions. | |
30 | |
31 @menu | |
32 * Defining Functions:: | |
33 * Multiple Return Values:: | |
34 * Variable-length Argument Lists:: | |
10209
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
35 * Ignoring Arguments:: |
3294 | 36 * Variable-length Return Lists:: |
37 * Returning From a Function:: | |
6510 | 38 * Default Arguments:: |
3294 | 39 * Function Files:: |
40 * Script Files:: | |
6638 | 41 * Function Handles Inline Functions and Anonymous Functions:: |
6549 | 42 * Commands:: |
3294 | 43 * Organization of Functions:: |
44 @end menu | |
45 | |
4167 | 46 @node Defining Functions |
3294 | 47 @section Defining Functions |
48 @cindex @code{function} statement | |
49 @cindex @code{endfunction} statement | |
50 | |
51 In its simplest form, the definition of a function named @var{name} | |
52 looks like this: | |
53 | |
54 @example | |
55 @group | |
56 function @var{name} | |
57 @var{body} | |
58 endfunction | |
59 @end group | |
60 @end example | |
61 | |
62 @noindent | |
63 A valid function name is like a valid variable name: a sequence of | |
64 letters, digits and underscores, not starting with a digit. Functions | |
65 share the same pool of names as variables. | |
66 | |
67 The function @var{body} consists of Octave statements. It is the | |
68 most important part of the definition, because it says what the function | |
69 should actually @emph{do}. | |
70 | |
71 For example, here is a function that, when executed, will ring the bell | |
72 on your terminal (assuming that it is possible to do so): | |
73 | |
74 @example | |
75 @group | |
76 function wakeup | |
77 printf ("\a"); | |
78 endfunction | |
79 @end group | |
80 @end example | |
81 | |
82 The @code{printf} statement (@pxref{Input and Output}) simply tells | |
83 Octave to print the string @code{"\a"}. The special character @samp{\a} | |
84 stands for the alert character (ASCII 7). @xref{Strings}. | |
85 | |
86 Once this function is defined, you can ask Octave to evaluate it by | |
87 typing the name of the function. | |
88 | |
89 Normally, you will want to pass some information to the functions you | |
90 define. The syntax for passing parameters to a function in Octave is | |
91 | |
92 @example | |
93 @group | |
94 function @var{name} (@var{arg-list}) | |
95 @var{body} | |
96 endfunction | |
97 @end group | |
98 @end example | |
99 | |
100 @noindent | |
101 where @var{arg-list} is a comma-separated list of the function's | |
102 arguments. When the function is called, the argument names are used to | |
103 hold the argument values given in the call. The list of arguments may | |
104 be empty, in which case this form is equivalent to the one shown above. | |
105 | |
106 To print a message along with ringing the bell, you might modify the | |
6510 | 107 @code{wakeup} to look like this: |
3294 | 108 |
109 @example | |
110 @group | |
111 function wakeup (message) | |
112 printf ("\a%s\n", message); | |
113 endfunction | |
114 @end group | |
115 @end example | |
116 | |
117 Calling this function using a statement like this | |
118 | |
119 @example | |
120 wakeup ("Rise and shine!"); | |
121 @end example | |
122 | |
123 @noindent | |
124 will cause Octave to ring your terminal's bell and print the message | |
125 @samp{Rise and shine!}, followed by a newline character (the @samp{\n} | |
126 in the first argument to the @code{printf} statement). | |
127 | |
128 In most cases, you will also want to get some information back from the | |
129 functions you define. Here is the syntax for writing a function that | |
130 returns a single value: | |
131 | |
132 @example | |
133 @group | |
134 function @var{ret-var} = @var{name} (@var{arg-list}) | |
135 @var{body} | |
136 endfunction | |
137 @end group | |
138 @end example | |
139 | |
140 @noindent | |
141 The symbol @var{ret-var} is the name of the variable that will hold the | |
142 value to be returned by the function. This variable must be defined | |
143 before the end of the function body in order for the function to return | |
144 a value. | |
145 | |
146 Variables used in the body of a function are local to the | |
147 function. Variables named in @var{arg-list} and @var{ret-var} are also | |
148 local to the function. @xref{Global Variables}, for information about | |
149 how to access global variables inside a function. | |
150 | |
151 For example, here is a function that computes the average of the | |
152 elements of a vector: | |
153 | |
154 @example | |
155 @group | |
156 function retval = avg (v) | |
157 retval = sum (v) / length (v); | |
158 endfunction | |
159 @end group | |
160 @end example | |
161 | |
162 If we had written @code{avg} like this instead, | |
163 | |
164 @example | |
165 @group | |
166 function retval = avg (v) | |
4029 | 167 if (isvector (v)) |
3294 | 168 retval = sum (v) / length (v); |
169 endif | |
170 endfunction | |
171 @end group | |
172 @end example | |
173 | |
174 @noindent | |
175 and then called the function with a matrix instead of a vector as the | |
176 argument, Octave would have printed an error message like this: | |
177 | |
178 @example | |
179 @group | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7984
diff
changeset
|
180 error: value on right hand side of assignment is undefined |
3294 | 181 @end group |
182 @end example | |
183 | |
184 @noindent | |
185 because the body of the @code{if} statement was never executed, and | |
186 @code{retval} was never defined. To prevent obscure errors like this, | |
187 it is a good idea to always make sure that the return variables will | |
188 always have values, and to produce meaningful error messages when | |
189 problems are encountered. For example, @code{avg} could have been | |
190 written like this: | |
191 | |
192 @example | |
193 @group | |
194 function retval = avg (v) | |
195 retval = 0; | |
4029 | 196 if (isvector (v)) |
3294 | 197 retval = sum (v) / length (v); |
198 else | |
199 error ("avg: expecting vector argument"); | |
200 endif | |
201 endfunction | |
202 @end group | |
203 @end example | |
204 | |
205 There is still one additional problem with this function. What if it is | |
206 called without an argument? Without additional error checking, Octave | |
207 will probably print an error message that won't really help you track | |
208 down the source of the error. To allow you to catch errors like this, | |
209 Octave provides each function with an automatic variable called | |
210 @code{nargin}. Each time a function is called, @code{nargin} is | |
211 automatically initialized to the number of arguments that have actually | |
212 been passed to the function. For example, we might rewrite the | |
213 @code{avg} function like this: | |
214 | |
215 @example | |
216 @group | |
217 function retval = avg (v) | |
218 retval = 0; | |
219 if (nargin != 1) | |
220 usage ("avg (vector)"); | |
221 endif | |
4029 | 222 if (isvector (v)) |
3294 | 223 retval = sum (v) / length (v); |
224 else | |
225 error ("avg: expecting vector argument"); | |
226 endif | |
227 endfunction | |
228 @end group | |
229 @end example | |
230 | |
231 Although Octave does not automatically report an error if you call a | |
232 function with more arguments than expected, doing so probably indicates | |
233 that something is wrong. Octave also does not automatically report an | |
234 error if a function is called with too few arguments, but any attempt to | |
235 use a variable that has not been given a value will result in an error. | |
236 To avoid such problems and to provide useful messages, we check for both | |
237 possibilities and issue our own error message. | |
238 | |
4700 | 239 @DOCSTRING(nargin) |
3294 | 240 |
6558 | 241 @DOCSTRING(inputname) |
242 | |
3371 | 243 @DOCSTRING(silent_functions) |
3294 | 244 |
4167 | 245 @node Multiple Return Values |
3294 | 246 @section Multiple Return Values |
247 | |
248 Unlike many other computer languages, Octave allows you to define | |
249 functions that return more than one value. The syntax for defining | |
250 functions that return multiple values is | |
251 | |
252 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
253 @group |
3294 | 254 function [@var{ret-list}] = @var{name} (@var{arg-list}) |
255 @var{body} | |
256 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
257 @end group |
3294 | 258 @end example |
259 | |
260 @noindent | |
261 where @var{name}, @var{arg-list}, and @var{body} have the same meaning | |
262 as before, and @var{ret-list} is a comma-separated list of variable | |
263 names that will hold the values returned from the function. The list of | |
264 return values must have at least one element. If @var{ret-list} has | |
265 only one element, this form of the @code{function} statement is | |
266 equivalent to the form described in the previous section. | |
267 | |
268 Here is an example of a function that returns two values, the maximum | |
269 element of a vector and the index of its first occurrence in the vector. | |
270 | |
271 @example | |
272 @group | |
273 function [max, idx] = vmax (v) | |
274 idx = 1; | |
275 max = v (idx); | |
276 for i = 2:length (v) | |
277 if (v (i) > max) | |
278 max = v (i); | |
279 idx = i; | |
280 endif | |
281 endfor | |
282 endfunction | |
283 @end group | |
284 @end example | |
285 | |
286 In this particular case, the two values could have been returned as | |
287 elements of a single array, but that is not always possible or | |
288 convenient. The values to be returned may not have compatible | |
289 dimensions, and it is often desirable to give the individual return | |
290 values distinct names. | |
291 | |
292 In addition to setting @code{nargin} each time a function is called, | |
293 Octave also automatically initializes @code{nargout} to the number of | |
294 values that are expected to be returned. This allows you to write | |
295 functions that behave differently depending on the number of values that | |
296 the user of the function has requested. The implicit assignment to the | |
297 built-in variable @code{ans} does not figure in the count of output | |
298 arguments, so the value of @code{nargout} may be zero. | |
299 | |
300 The @code{svd} and @code{lu} functions are examples of built-in | |
301 functions that behave differently depending on the value of | |
302 @code{nargout}. | |
303 | |
304 It is possible to write functions that only set some return values. For | |
305 example, calling the function | |
306 | |
307 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
308 @group |
3294 | 309 function [x, y, z] = f () |
310 x = 1; | |
311 z = 2; | |
312 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
313 @end group |
3294 | 314 @end example |
315 | |
316 @noindent | |
317 as | |
318 | |
319 @example | |
320 [a, b, c] = f () | |
321 @end example | |
322 | |
323 @noindent | |
324 produces: | |
325 | |
326 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
327 @group |
3294 | 328 a = 1 |
329 | |
330 b = [](0x0) | |
331 | |
332 c = 2 | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
333 @end group |
3294 | 334 @end example |
335 | |
336 @noindent | |
6501 | 337 along with a warning. |
3294 | 338 |
4700 | 339 @DOCSTRING(nargout) |
3294 | 340 |
3371 | 341 @DOCSTRING(nargchk) |
3294 | 342 |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
343 @DOCSTRING(nargoutchk) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
344 |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8276
diff
changeset
|
345 @anchor{doc-varargin} @anchor{doc-varargout} |
4167 | 346 @node Variable-length Argument Lists |
3294 | 347 @section Variable-length Argument Lists |
4933 | 348 @cindex variable-length argument lists |
8567 | 349 @cindex @code{varargin} |
8072 | 350 |
6510 | 351 Sometimes the number of input arguments is not known when the function |
352 is defined. As an example think of a function that returns the smallest | |
353 of all its input arguments. For example, | |
354 | |
355 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
356 @group |
6510 | 357 a = smallest (1, 2, 3); |
358 b = smallest (1, 2, 3, 4); | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
359 @end group |
6510 | 360 @end example |
361 | |
362 @noindent | |
363 In this example both @code{a} and @code{b} would be 1. One way to write | |
364 the @code{smallest} function is | |
365 | |
366 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
367 @group |
6510 | 368 function val = smallest (arg1, arg2, arg3, arg4, arg5) |
369 @var{body} | |
370 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
371 @end group |
6510 | 372 @end example |
373 | |
374 @noindent | |
375 and then use the value of @code{nargin} to determine which of the input | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
376 arguments should be considered. The problem with this approach is |
6510 | 377 that it can only handle a limited number of input arguments. |
378 | |
7588
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
379 If the special parameter name @code{varargin} appears at the end of a |
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
380 function parameter list it indicates that the function takes a variable |
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
381 number of input arguments. Using @code{varargin} the function |
6510 | 382 looks like this |
383 | |
384 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
385 @group |
6510 | 386 function val = smallest (varargin) |
387 @var{body} | |
388 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
389 @end group |
6510 | 390 @end example |
391 | |
392 @noindent | |
393 In the function body the input arguments can be accessed through the | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
394 variable @code{varargin}. This variable is a cell array containing |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
395 all the input arguments. @xref{Cell Arrays}, for details on working |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
396 with cell arrays. The @code{smallest} function can now be defined |
6510 | 397 like this |
398 | |
399 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
400 @group |
6510 | 401 function val = smallest (varargin) |
402 val = min ([varargin@{:@}]); | |
403 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
404 @end group |
6510 | 405 @end example |
406 | |
407 @noindent | |
408 This implementation handles any number of input arguments, but it's also | |
409 a very simple solution to the problem. | |
410 | |
411 A slightly more complex example of @code{varargin} is a function | |
412 @code{print_arguments} that prints all input arguments. Such a function | |
413 can be defined like this | |
414 | |
415 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
416 @group |
6510 | 417 function print_arguments (varargin) |
418 for i = 1:length (varargin) | |
419 printf ("Input argument %d: ", i); | |
420 disp (varargin@{i@}); | |
421 endfor | |
422 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
423 @end group |
6510 | 424 @end example |
425 | |
426 @noindent | |
427 This function produces output like this | |
428 | |
429 @example | |
430 @group | |
431 print_arguments (1, "two", 3); | |
432 @print{} Input argument 1: 1 | |
433 @print{} Input argument 2: two | |
434 @print{} Input argument 3: 3 | |
435 @end group | |
436 @end example | |
3294 | 437 |
6558 | 438 @DOCSTRING(parseparams) |
439 | |
10209
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
440 @node Ignoring Arguments |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
441 @section Ignoring Arguments |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
442 |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
443 In the formal argument list, it is possible to use the dummy placeholder @code{~} |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
444 instead of a name. This indicates that the corresponding argument value should be ignored |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
445 and not stored to any variable. |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
446 |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
447 @example |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
448 @group |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
449 function val = pick2nd (~, arg2) |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
450 val = arg2; |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
451 endfunction |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
452 @end group |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
453 @end example |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
454 |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
455 The value of @code{nargin} is not affected by using this declaration. |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
456 |
4167 | 457 @node Variable-length Return Lists |
3294 | 458 @section Variable-length Return Lists |
4933 | 459 @cindex variable-length return lists |
8567 | 460 @cindex @code{varargout} |
8072 | 461 |
6510 | 462 It is possible to return a variable number of output arguments from a |
463 function using a syntax that's similar to the one used with the | |
7588
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
464 special @code{varargin} parameter name. To let a function return a |
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
465 variable number of output arguments the special output parameter name |
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
466 @code{varargout} is used. As with @code{varargin}, @code{varargout} is |
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
467 a cell array that will contain the requested output arguments. |
6510 | 468 |
469 As an example the following function sets the first output argument to | |
470 1, the second to 2, and so on. | |
471 | |
472 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
473 @group |
6510 | 474 function varargout = one_to_n () |
475 for i = 1:nargout | |
476 varargout@{i@} = i; | |
477 endfor | |
478 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
479 @end group |
6510 | 480 @end example |
481 | |
482 @noindent | |
483 When called this function returns values like this | |
484 | |
485 @example | |
486 @group | |
487 [a, b, c] = one_to_n () | |
488 @result{} a = 1 | |
489 @result{} b = 2 | |
490 @result{} c = 3 | |
491 @end group | |
492 @end example | |
3294 | 493 |
7588
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
494 If @code{varargin} (@code{varargout}) does not appear as the last |
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
495 element of the input (output) parameter list, then it is not special, |
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
496 and is handled the same as any other parameter name. |
cbedf652a752
doc fix for varargin and varargout change
John W. Eaton <jwe@octave.org>
parents:
7031
diff
changeset
|
497 |
6558 | 498 @DOCSTRING(deal) |
499 | |
4167 | 500 @node Returning From a Function |
3294 | 501 @section Returning From a Function |
502 | |
503 The body of a user-defined function can contain a @code{return} statement. | |
504 This statement returns control to the rest of the Octave program. It | |
505 looks like this: | |
506 | |
507 @example | |
508 return | |
509 @end example | |
510 | |
511 Unlike the @code{return} statement in C, Octave's @code{return} | |
512 statement cannot be used to return a value from a function. Instead, | |
513 you must assign values to the list of return variables that are part of | |
514 the @code{function} statement. The @code{return} statement simply makes | |
515 it easier to exit a function from a deeply nested loop or conditional | |
516 statement. | |
517 | |
518 Here is an example of a function that checks to see if any elements of a | |
519 vector are nonzero. | |
520 | |
521 @example | |
522 @group | |
523 function retval = any_nonzero (v) | |
524 retval = 0; | |
525 for i = 1:length (v) | |
526 if (v (i) != 0) | |
527 retval = 1; | |
528 return; | |
529 endif | |
530 endfor | |
531 printf ("no nonzero elements found\n"); | |
532 endfunction | |
533 @end group | |
534 @end example | |
535 | |
536 Note that this function could not have been written using the | |
537 @code{break} statement to exit the loop once a nonzero value is found | |
538 without adding extra logic to avoid printing the message if the vector | |
539 does contain a nonzero element. | |
540 | |
5763 | 541 @deffn {Keyword} return |
3294 | 542 When Octave encounters the keyword @code{return} inside a function or |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
543 script, it returns control to the caller immediately. At the top level, |
3294 | 544 the return statement is ignored. A @code{return} statement is assumed |
545 at the end of every function definition. | |
5763 | 546 @end deffn |
3294 | 547 |
6510 | 548 @node Default Arguments |
549 @section Default Arguments | |
550 @cindex default arguments | |
551 | |
552 Since Octave supports variable number of input arguments, it is very useful | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
553 to assign default values to some input arguments. When an input argument |
6510 | 554 is declared in the argument list it is possible to assign a default |
555 value to the argument like this | |
556 | |
557 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
558 @group |
6510 | 559 function @var{name} (@var{arg1} = @var{val1}, @dots{}) |
560 @var{body} | |
561 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
562 @end group |
6510 | 563 @end example |
564 | |
565 @noindent | |
566 If no value is assigned to @var{arg1} by the user, it will have the | |
567 value @var{val1}. | |
568 | |
569 As an example, the following function implements a variant of the classic | |
570 ``Hello, World'' program. | |
571 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
572 @group |
6510 | 573 function hello (who = "World") |
574 printf ("Hello, %s!\n", who); | |
575 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
576 @end group |
6510 | 577 @end example |
578 | |
579 @noindent | |
580 When called without an input argument the function prints the following | |
581 @example | |
582 @group | |
583 hello (); | |
584 @print{} Hello, World! | |
585 @end group | |
586 @end example | |
587 | |
588 @noindent | |
589 and when it's called with an input argument it prints the following | |
590 @example | |
591 @group | |
592 hello ("Beautiful World of Free Software"); | |
593 @print{} Hello, Beautiful World of Free Software! | |
594 @end group | |
595 @end example | |
596 | |
597 Sometimes it is useful to explicitly tell Octave to use the default value | |
598 of an input argument. This can be done writing a @samp{:} as the value | |
599 of the input argument when calling the function. | |
600 @example | |
601 @group | |
602 hello (:); | |
603 @print{} Hello, World! | |
604 @end group | |
605 @end example | |
606 | |
4167 | 607 @node Function Files |
3294 | 608 @section Function Files |
609 @cindex function file | |
610 | |
611 Except for simple one-shot programs, it is not practical to have to | |
612 define all the functions you need each time you need them. Instead, you | |
613 will normally want to save them in a file so that you can easily edit | |
614 them, and save them for use at a later time. | |
615 | |
616 Octave does not require you to load function definitions from files | |
617 before using them. You simply need to put the function definitions in a | |
618 place where Octave can find them. | |
619 | |
620 When Octave encounters an identifier that is undefined, it first looks | |
621 for variables or functions that are already compiled and currently | |
622 listed in its symbol table. If it fails to find a definition there, it | |
6556 | 623 searches a list of directories (the @dfn{path}) for files ending in |
6554 | 624 @file{.m} that have the same base name as the undefined |
625 identifier.@footnote{The @samp{.m} suffix was chosen for compatibility | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
626 with @sc{matlab}.} Once Octave finds a file with a name that matches, |
6554 | 627 the contents of the file are read. If it defines a @emph{single} |
628 function, it is compiled and executed. @xref{Script Files}, for more | |
629 information about how you can define more than one function in a single | |
630 file. | |
3294 | 631 |
632 When Octave defines a function from a function file, it saves the full | |
6554 | 633 name of the file it read and the time stamp on the file. If the time |
634 stamp on the file changes, Octave may reload the file. When Octave is | |
635 running interactively, time stamp checking normally happens at most once | |
636 each time Octave prints the prompt. Searching for new function | |
637 definitions also occurs if the current working directory changes. | |
3294 | 638 |
639 Checking the time stamp allows you to edit the definition of a function | |
640 while Octave is running, and automatically use the new function | |
6554 | 641 definition without having to restart your Octave session. |
3294 | 642 |
643 To avoid degrading performance unnecessarily by checking the time stamps | |
644 on functions that are not likely to change, Octave assumes that function | |
645 files in the directory tree | |
646 @file{@var{octave-home}/share/octave/@var{version}/m} | |
647 will not change, so it doesn't have to check their time stamps every time the | |
648 functions defined in those files are used. This is normally a very good | |
649 assumption and provides a significant improvement in performance for the | |
650 function files that are distributed with Octave. | |
651 | |
652 If you know that your own function files will not change while you are | |
6554 | 653 running Octave, you can improve performance by calling |
654 @code{ignore_function_time_stamp ("all")}, so that Octave will | |
655 ignore the time stamps for all function files. Passing | |
656 @code{"system"} to this function resets the default behavior. | |
3294 | 657 |
5775 | 658 @c FIXME -- note about time stamps on files in NFS environments? |
3294 | 659 |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8567
diff
changeset
|
660 @DOCSTRING(edit) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8567
diff
changeset
|
661 |
6549 | 662 @DOCSTRING(mfilename) |
663 | |
6638 | 664 @DOCSTRING(ignore_function_time_stamp) |
665 | |
666 @menu | |
667 * Manipulating the load path:: | |
668 * Subfunctions:: | |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
669 * Private Functions:: |
6638 | 670 * Overloading and Autoloading:: |
671 * Function Locking:: | |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
672 * Function Precedence:: |
6638 | 673 @end menu |
674 | |
675 @node Manipulating the load path | |
676 @subsection Manipulating the load path | |
677 | |
8828 | 678 When a function is called, Octave searches a list of directories for |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
679 a file that contains the function declaration. This list of directories |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
680 is known as the load path. By default the load path contains |
6638 | 681 a list of directories distributed with Octave plus the current |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
682 working directory. To see your current load path call the @code{path} |
6638 | 683 function without any input or output arguments. |
684 | |
685 It is possible to add or remove directories to or from the load path | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
686 using @code{addpath} and @code{rmpath}. As an example, the following |
6638 | 687 code adds @samp{~/Octave} to the load path. |
688 | |
689 @example | |
690 addpath("~/Octave") | |
691 @end example | |
692 | |
693 @noindent | |
694 After this the directory @samp{~/Octave} will be searched for functions. | |
695 | |
6502 | 696 @DOCSTRING(addpath) |
697 | |
698 @DOCSTRING(genpath) | |
699 | |
700 @DOCSTRING(rmpath) | |
701 | |
702 @DOCSTRING(savepath) | |
703 | |
6477 | 704 @DOCSTRING(path) |
3294 | 705 |
6502 | 706 @DOCSTRING(pathdef) |
707 | |
708 @DOCSTRING(pathsep) | |
709 | |
3428 | 710 @DOCSTRING(rehash) |
711 | |
712 @DOCSTRING(file_in_loadpath) | |
713 | |
7638
2df457529cfa
implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7588
diff
changeset
|
714 @DOCSTRING(restoredefaultpath) |
2df457529cfa
implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7588
diff
changeset
|
715 |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8567
diff
changeset
|
716 @DOCSTRING(command_line_path) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8567
diff
changeset
|
717 |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8567
diff
changeset
|
718 @DOCSTRING(find_dir_in_path) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8567
diff
changeset
|
719 |
6556 | 720 @node Subfunctions |
721 @subsection Subfunctions | |
722 | |
723 A function file may contain secondary functions called | |
724 @dfn{subfunctions}. These secondary functions are only visible to the | |
725 other functions in the same function file. For example, a file | |
726 @file{f.m} containing | |
727 | |
728 @example | |
729 @group | |
730 function f () | |
731 printf ("in f, calling g\n"); | |
732 g () | |
733 endfunction | |
734 function g () | |
735 printf ("in g, calling h\n"); | |
6638 | 736 h () |
6556 | 737 endfunction |
738 function h () | |
739 printf ("in h\n") | |
740 endfunction | |
741 @end group | |
742 @end example | |
743 | |
744 @noindent | |
745 defines a main function @code{f} and two subfunctions. The | |
746 subfunctions @code{g} and @code{h} may only be called from the main | |
747 function @code{f} or from the other subfunctions, but not from outside | |
748 the file @file{f.m}. | |
749 | |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
750 @node Private Functions |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
751 @subsection Private Functions |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
752 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
753 In many cases one function needs to access one or more helper |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
754 functions. If the helper function is limited to the scope of a single |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
755 function, then subfunctions as discussed above might be used. However, |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
756 if a single helper function is used by more than one function, then |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
757 this is no longer possible. In this case the helper functions might |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
758 be placed in a subdirectory, called "private", of the directory in which |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
759 the functions needing access to this helper function are found. |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
760 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
761 As a simple example, consider a function @code{func1}, that calls a helper |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
762 function @code{func2} to do much of the work. For example |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
763 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
764 @example |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
765 @group |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
766 function y = func1 (x) |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
767 y = func2 (x); |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
768 endfunction |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
769 @end group |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
770 @end example |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
771 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
772 @noindent |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
773 Then if the path to @code{func1} is @code{<directory>/func1.m}, and if |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
774 @code{func2} is found in the directory @code{<directory>/private/func2.m}, |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
775 then @code{func2} is only available for use of the functions, like |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
776 @code{func1}, that are found in @code{<directory>}. |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
777 |
6635 | 778 @node Overloading and Autoloading |
779 @subsection Overloading and Autoloading | |
780 | |
781 The @code{dispatch} function can be used to alias one function name to | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
782 another. It can be used to alias all calls to a particular function name |
6635 | 783 to another function, or the alias can be limited to only a particular |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
784 variable type. Consider the example |
6635 | 785 |
786 @example | |
787 @group | |
788 function y = spsin (x) | |
789 printf ("Calling spsin\n"); | |
790 fflush(stdout); | |
791 y = spfun ("sin", x); | |
792 endfunction | |
793 | |
794 dispatch ("sin", "spsin", "sparse matrix"); | |
795 y0 = sin(eye(3)); | |
796 y1 = sin(speye(3)); | |
797 @end group | |
798 @end example | |
799 | |
800 @noindent | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
801 which aliases the user-defined function @code{spsin} to @code{sin}, but only for real sparse |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
802 matrices. Note that the builtin @code{sin} already correctly treats |
6635 | 803 sparse matrices and so this example is only illustrative. |
804 | |
805 @DOCSTRING(dispatch) | |
806 | |
807 @DOCSTRING(builtin) | |
808 | |
809 A single dynamically linked file might define several | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
810 functions. However, as Octave searches for functions based on the |
6635 | 811 functions filename, Octave needs a manner in which to find each of the |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
812 functions in the dynamically linked file. On operating systems that |
6635 | 813 support symbolic links, it is possible to create a symbolic link to the |
814 original file for each of the functions which it contains. | |
815 | |
816 However, there is at least one well known operating system that doesn't | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
817 support symbolic links. Making copies of the original file for each of |
8828 | 818 the functions is undesirable as it increases the |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
819 amount of disk space used by Octave. Instead Octave supplies the |
6635 | 820 @code{autoload} function, that permits the user to define in which |
821 file a certain function will be found. | |
822 | |
823 @DOCSTRING(autoload) | |
824 | |
825 @node Function Locking | |
826 @subsection Function Locking | |
827 | |
828 It is sometime desirable to lock a function into memory with the | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
829 @code{mlock} function. This is typically used for dynamically linked |
6899 | 830 functions in Oct-files or mex-files that contain some initialization, |
831 and it is desirable that calling @code{clear} does not remove this | |
6635 | 832 initialization. |
833 | |
6899 | 834 As an example, |
835 | |
836 @example | |
837 mlock ("my_function"); | |
838 @end example | |
839 | |
840 @noindent | |
841 prevents @code{my_function} from being removed from memory, even if | |
842 @code{clear} is called. It is possible to determine if a function is | |
843 locked into memory with the @code{mislocked}, and to unlock a function | |
844 with @code{munlock}, which the following illustrates. | |
845 | |
846 @example | |
847 @group | |
848 mlock ("my_function"); | |
849 mislocked ("my_function") | |
850 @result{} ans = 1 | |
851 munlock ("my_function"); | |
852 mislocked ("my_function") | |
853 @result{} ans = 0 | |
854 @end group | |
855 @end example | |
856 | |
857 A common use of @code{mlock} is to prevent persistent variables from | |
8828 | 858 being removed from memory, as the following example shows: |
6899 | 859 |
860 @example | |
861 @group | |
862 function count_calls() | |
863 persistent calls = 0; | |
7031 | 864 printf ("'count_calls' has been called %d times\n", |
865 ++calls); | |
6899 | 866 endfunction |
867 mlock ("count_calls"); | |
868 | |
869 count_calls (); | |
870 @print{} 'count_calls' has been called 1 times | |
871 | |
872 clear count_calls | |
873 count_calls (); | |
874 @print{} 'count_calls' has been called 2 times | |
875 @end group | |
876 @end example | |
877 | |
878 @noindent | |
879 It is, however, often inconvenient to lock a function from the prompt, | |
880 so it is also possible to lock a function from within its body. This | |
881 is simply done by calling @code{mlock} from within the function. | |
882 | |
883 @example | |
884 @group | |
885 function count_calls () | |
886 mlock (); | |
887 persistent calls = 0; | |
7031 | 888 printf ("'count_calls' has been called %d times\n", |
889 ++calls); | |
6899 | 890 endfunction |
891 @end group | |
892 @end example | |
893 | |
894 @code{mlock} might equally be used to prevent changes to a function from having | |
6635 | 895 effect in Octave, though a similar effect can be had with the |
896 @code{ignore_function_time_stamp} function. | |
897 | |
898 @DOCSTRING(mlock) | |
899 | |
900 @DOCSTRING(munlock) | |
901 | |
902 @DOCSTRING(mislocked) | |
903 | |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
904 @node Function Precedence |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
905 @subsection Function Precedence |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
906 |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
907 Given the numerous different ways that Octave can define a function, it |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
908 is possible and even likely that multiple versions of a function, might be |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
909 defined within a particular scope. The precedence of which function will be |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
910 used within a particular scope is given by |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
911 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
912 @enumerate 1 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
913 @item Subfunction |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
914 A subfunction with the required function name in the given scope. |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
915 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
916 @item Private function |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
917 A function defined within a private directory of the directory |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
918 which contains the current function. |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
919 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
920 @item Class constructor |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
921 A function that constuctors a user class as defined in chapter |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
922 @ref{Object Oriented Programming}. |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
923 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
924 @item Class method |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
925 An overloaded function of a class as in chapter |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
926 @ref{Object Oriented Programming}. |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
927 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
928 @item Legacy Dispatch |
8235 | 929 An overloaded function as defined by @xref{doc-dispatch}. |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
930 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
931 @item Command-line Function |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
932 A function that has been defined on the command-line. |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
933 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
934 @item Autoload function |
8235 | 935 A function that is marked as autoloaded with @xref{doc-autoload}. |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
936 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
937 @item A Function on the Path |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
938 A function that can be found on the users load-path. There can also be |
8221
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
939 Oct-file, mex-file or m-file versions of this function and the precedence |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
940 between these versions are in that order. |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
941 |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
942 @item Built-in function |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
943 A function that is builtin to Octave itself such as @code{numel}, |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
944 @code{size}, etc. |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
945 @end enumerate |
06094fa570a3
Add some documentation for the OOP code of Octave
David Bateman <dbateman@free.fr>
parents:
8074
diff
changeset
|
946 |
4167 | 947 @node Script Files |
3294 | 948 @section Script Files |
949 | |
950 A script file is a file containing (almost) any sequence of Octave | |
951 commands. It is read and evaluated just as if you had typed each | |
952 command at the Octave prompt, and provides a convenient way to perform a | |
953 sequence of commands that do not logically belong inside a function. | |
954 | |
955 Unlike a function file, a script file must @emph{not} begin with the | |
956 keyword @code{function}. If it does, Octave will assume that it is a | |
957 function file, and that it defines a single function that should be | |
958 evaluated as soon as it is defined. | |
959 | |
960 A script file also differs from a function file in that the variables | |
961 named in a script file are not local variables, but are in the same | |
962 scope as the other variables that are visible on the command line. | |
963 | |
964 Even though a script file may not begin with the @code{function} | |
965 keyword, it is possible to define more than one function in a single | |
966 script file and load (but not execute) all of them at once. To do | |
967 this, the first token in the file (ignoring comments and other white | |
968 space) must be something other than @code{function}. If you have no | |
969 other statements to evaluate, you can use a statement that has no | |
970 effect, like this: | |
971 | |
972 @example | |
973 @group | |
974 # Prevent Octave from thinking that this | |
975 # is a function file: | |
976 | |
977 1; | |
978 | |
979 # Define function one: | |
980 | |
981 function one () | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
982 @dots{} |
3294 | 983 @end group |
984 @end example | |
985 | |
986 To have Octave read and compile these functions into an internal form, | |
6638 | 987 you need to make sure that the file is in Octave's load path |
6477 | 988 (accessible through the @code{path} function), then simply type the |
989 base name of the file that contains the commands. (Octave uses the | |
990 same rules to search for script files as it does to search for | |
991 function files.) | |
3294 | 992 |
993 If the first token in a file (ignoring comments) is @code{function}, | |
994 Octave will compile the function and try to execute it, printing a | |
995 message warning about any non-whitespace characters that appear after | |
996 the function definition. | |
997 | |
998 Note that Octave does not try to look up the definition of any identifier | |
999 until it needs to evaluate it. This means that Octave will compile the | |
1000 following statements if they appear in a script file, or are typed at | |
1001 the command line, | |
1002 | |
1003 @example | |
1004 @group | |
1005 # not a function file: | |
1006 1; | |
1007 function foo () | |
1008 do_something (); | |
1009 endfunction | |
1010 function do_something () | |
1011 do_something_else (); | |
1012 endfunction | |
1013 @end group | |
1014 @end example | |
1015 | |
1016 @noindent | |
1017 even though the function @code{do_something} is not defined before it is | |
1018 referenced in the function @code{foo}. This is not an error because | |
1019 Octave does not need to resolve all symbols that are referenced by a | |
1020 function until the function is actually evaluated. | |
1021 | |
1022 Since Octave doesn't look for definitions until they are needed, the | |
1023 following code will always print @samp{bar = 3} whether it is typed | |
1024 directly on the command line, read from a script file, or is part of a | |
1025 function body, even if there is a function or script file called | |
6477 | 1026 @file{bar.m} in Octave's path. |
3294 | 1027 |
1028 @example | |
1029 @group | |
1030 eval ("bar = 3"); | |
1031 bar | |
1032 @end group | |
1033 @end example | |
1034 | |
1035 Code like this appearing within a function body could fool Octave if | |
1036 definitions were resolved as the function was being compiled. It would | |
1037 be virtually impossible to make Octave clever enough to evaluate this | |
1038 code in a consistent fashion. The parser would have to be able to | |
1039 perform the call to @code{eval} at compile time, and that would be | |
1040 impossible unless all the references in the string to be evaluated could | |
1041 also be resolved, and requiring that would be too restrictive (the | |
1042 string might come from user input, or depend on things that are not | |
1043 known until the function is evaluated). | |
1044 | |
1045 Although Octave normally executes commands from script files that have | |
1046 the name @file{@var{file}.m}, you can use the function @code{source} to | |
1047 execute commands from any file. | |
1048 | |
3371 | 1049 @DOCSTRING(source) |
3294 | 1050 |
6638 | 1051 @node Function Handles Inline Functions and Anonymous Functions |
1052 @section Function Handles, Inline Functions, and Anonymous Functions | |
4933 | 1053 @cindex handle, function handles |
1054 @cindex inline, inline functions | |
6638 | 1055 @cindex anonymous functions |
4933 | 1056 |
6638 | 1057 It can be very convenient store a function in a variable so that it |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
1058 can be passed to a different function. For example, a function that |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
1059 performs numerical minimization needs access to the function that |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
1060 should be minimized. |
4933 | 1061 |
1062 @menu | |
1063 * Function Handles:: | |
6554 | 1064 * Anonymous Functions:: |
4933 | 1065 * Inline Functions:: |
1066 @end menu | |
1067 | |
1068 @node Function Handles | |
1069 @subsection Function Handles | |
1070 | |
6554 | 1071 A function handle is a pointer to another function and is defined with |
1072 the syntax | |
1073 | |
1074 @example | |
1075 @@@var{function-name} | |
1076 @end example | |
1077 | |
1078 @noindent | |
1079 For example | |
1080 | |
1081 @example | |
6556 | 1082 f = @@sin; |
6554 | 1083 @end example |
1084 | |
1085 @noindent | |
6570 | 1086 Creates a function handle called @code{f} that refers to the |
6554 | 1087 function @code{sin}. |
1088 | |
1089 Function handles are used to call other functions indirectly, or to pass | |
1090 a function as an argument to another function like @code{quad} or | |
1091 @code{fsolve}. For example | |
1092 | |
1093 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1094 @group |
6556 | 1095 f = @@sin; |
6554 | 1096 quad (f, 0, pi) |
6929 | 1097 @result{} 2 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1098 @end group |
6554 | 1099 @end example |
1100 | |
1101 You may use @code{feval} to call a function using function handle, or | |
6570 | 1102 simply write the name of the function handle followed by an argument |
6554 | 1103 list. If there are no arguments, you must use an empty argument list |
1104 @samp{()}. For example | |
1105 | |
1106 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1107 @group |
6556 | 1108 f = @@sin; |
6554 | 1109 feval (f, pi/4) |
6570 | 1110 @result{} 0.70711 |
6554 | 1111 f (pi/4) |
6570 | 1112 @result{} 0.70711 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1113 @end group |
6554 | 1114 @end example |
1115 | |
4933 | 1116 @DOCSTRING(functions) |
1117 | |
1118 @DOCSTRING(func2str) | |
1119 | |
1120 @DOCSTRING(str2func) | |
1121 | |
6570 | 1122 @node Anonymous Functions |
6554 | 1123 @subsection Anonymous Functions |
1124 | |
1125 Anonymous functions are defined using the syntax | |
1126 | |
1127 @example | |
1128 @@(@var{argument-list}) @var{expression} | |
1129 @end example | |
1130 | |
1131 @noindent | |
1132 Any variables that are not found in the argument list are inherited from | |
1133 the enclosing scope. Anonymous functions are useful for creating simple | |
1134 unnamed functions from expressions or for wrapping calls to other | |
1135 functions to adapt them for use by functions like @code{quad}. For | |
1136 example, | |
1137 | |
1138 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1139 @group |
6554 | 1140 f = @@(x) x.^2; |
1141 quad (f, 0, 10) | |
6570 | 1142 @result{} 333.33 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1143 @end group |
6554 | 1144 @end example |
1145 | |
1146 @noindent | |
1147 creates a simple unnamed function from the expression @code{x.^2} and | |
1148 passes it to @code{quad}, | |
1149 | |
1150 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1151 @group |
6554 | 1152 quad (@@(x) sin (x), 0, pi) |
6933 | 1153 @result{} 2 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1154 @end group |
6554 | 1155 @end example |
1156 | |
1157 @noindent | |
1158 wraps another function, and | |
1159 | |
1160 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1161 @group |
6554 | 1162 a = 1; |
1163 b = 2; | |
1164 quad (@@(x) betainc (x, a, b), 0, 0.4) | |
6929 | 1165 @result{} 0.13867 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
1166 @end group |
6554 | 1167 @end example |
1168 | |
1169 @noindent | |
1170 adapts a function with several parameters to the form required by | |
1171 @code{quad}. In this example, the values of @var{a} and @var{b} that | |
1172 are passed to @code{betainc} are inherited from the current | |
1173 environment. | |
1174 | |
4933 | 1175 @node Inline Functions |
1176 @subsection Inline Functions | |
1177 | |
6638 | 1178 An inline function is created from a string containing the function |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
1179 body using the @code{inline} function. The following code defines the |
6638 | 1180 function @math{f(x) = x^2 + 2}. |
1181 | |
1182 @example | |
1183 f = inline("x^2 + 2"); | |
1184 @end example | |
1185 | |
1186 @noindent | |
1187 After this it is possible to evaluate @math{f} at any @math{x} by | |
1188 writing @code{f(x)}. | |
1189 | |
4933 | 1190 @DOCSTRING(inline) |
1191 | |
1192 @DOCSTRING(argnames) | |
1193 | |
1194 @DOCSTRING(formula) | |
1195 | |
1196 @DOCSTRING(vectorize) | |
1197 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
1198 @DOCSTRING(symvar) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
1199 |
6549 | 1200 @node Commands |
1201 @section Commands | |
1202 | |
6638 | 1203 Commands are a special class of functions that only accept string |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
1204 input arguments. A command can be called as an ordinary function, but |
6638 | 1205 it can also be called without the parentheses like the following example |
1206 shows | |
1207 | |
1208 @example | |
1209 my_command hello world | |
1210 @end example | |
1211 | |
1212 @noindent | |
1213 which is the same as | |
1214 | |
1215 @example | |
1216 my_command("hello", "world") | |
1217 @end example | |
1218 | |
1219 The general form of a command call is | |
1220 | |
1221 @example | |
1222 @var{name} @var{arg1} @var{arg2} @dots{} | |
1223 @end example | |
1224 | |
1225 @noindent | |
1226 which translates directly to | |
1227 | |
1228 @example | |
1229 @var{name} ("@var{arg1}", "@var{arg2}", @dots{}) | |
1230 @end example | |
1231 | |
7001 | 1232 A function can be used as a command if it accepts string input arguments. |
6638 | 1233 To do this, the function must be marked as a command, which can be done |
1234 with the @code{mark_as_command} command like this | |
1235 | |
1236 @example | |
1237 mark_as_command name | |
1238 @end example | |
1239 | |
1240 @noindent | |
1241 where @code{name} is the function to be marked as a command. | |
1242 | |
1243 One difficulty of commands occurs when one of the string input arguments | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
1244 are stored in a variable. Since Octave can't tell the difference between |
6638 | 1245 a variable name, and an ordinary string, it is not possible to pass a |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
9032
diff
changeset
|
1246 variable as input to a command. In such a situation a command must be |
6638 | 1247 called as a function. |
1248 | |
6549 | 1249 @DOCSTRING(mark_as_command) |
1250 | |
1251 @DOCSTRING(unmark_command) | |
1252 | |
1253 @DOCSTRING(iscommand) | |
1254 | |
1255 @DOCSTRING(mark_as_rawcommand) | |
1256 | |
1257 @DOCSTRING(unmark_rawcommand) | |
1258 | |
1259 @DOCSTRING(israwcommand) | |
1260 | |
4167 | 1261 @node Organization of Functions |
3294 | 1262 @section Organization of Functions Distributed with Octave |
1263 | |
1264 Many of Octave's standard functions are distributed as function files. | |
1265 They are loosely organized by topic, in subdirectories of | |
1266 @file{@var{octave-home}/lib/octave/@var{version}/m}, to make it easier | |
1267 to find them. | |
1268 | |
1269 The following is a list of all the function file subdirectories, and the | |
1270 types of functions you will find there. | |
1271 | |
1272 @table @file | |
1273 @item audio | |
1274 Functions for playing and recording sounds. | |
1275 | |
1276 @item control | |
1277 Functions for design and simulation of automatic control systems. | |
1278 | |
1279 @item elfun | |
1280 Elementary functions. | |
1281 | |
6554 | 1282 @item finance |
1283 Functions for computing interest payments, investment values, and rates | |
1284 of return. | |
1285 | |
3294 | 1286 @item general |
1287 Miscellaneous matrix manipulations, like @code{flipud}, @code{rot90}, | |
1288 and @code{triu}, as well as other basic functions, like | |
4029 | 1289 @code{ismatrix}, @code{nargchk}, etc. |
3294 | 1290 |
1291 @item image | |
1292 Image processing tools. These functions require the X Window System. | |
1293 | |
1294 @item io | |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
8286
diff
changeset
|
1295 Input-output functions. |
3294 | 1296 |
1297 @item linear-algebra | |
1298 Functions for linear algebra. | |
1299 | |
1300 @item miscellaneous | |
1301 Functions that don't really belong anywhere else. | |
1302 | |
6554 | 1303 @item optimization |
1304 Minimization of functions. | |
1305 | |
1306 @item path | |
1307 Functions to manage the directory path Octave uses to find functions. | |
1308 | |
1309 @item pkg | |
1310 Install external packages of functions in Octave. | |
1311 | |
3294 | 1312 @item plot |
6556 | 1313 Functions for displaying and printing two- and three-dimensional graphs. |
3294 | 1314 |
1315 @item polynomial | |
1316 Functions for manipulating polynomials. | |
1317 | |
1318 @item set | |
1319 Functions for creating and manipulating sets of unique values. | |
1320 | |
1321 @item signal | |
1322 Functions for signal processing applications. | |
1323 | |
6554 | 1324 @item sparse |
1325 Functions for handling sparse matrices. | |
1326 | |
3294 | 1327 @item specfun |
1328 Special functions. | |
1329 | |
1330 @item special-matrix | |
1331 Functions that create special matrix forms. | |
1332 | |
1333 @item startup | |
1334 Octave's system-wide startup file. | |
1335 | |
1336 @item statistics | |
1337 Statistical functions. | |
1338 | |
1339 @item strings | |
1340 Miscellaneous string-handling functions. | |
1341 | |
6554 | 1342 @item testfun |
1343 Perform unit tests on other functions. | |
1344 | |
3294 | 1345 @item time |
1346 Functions related to time keeping. | |
1347 @end table |