home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / doc / octave.i02 < prev    next >
Encoding:
GNU Info File  |  1999-05-13  |  48.3 KB  |  1,450 lines

  1. This is Info file octave, produced by Makeinfo-1.64 from the input file
  2. octave.tex.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Octave: (octave).    Interactive language for numerical computations.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    Copyright (C) 1996, 1997 John W. Eaton.
  9.  
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.  
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided that
  16. the entire resulting derived work is distributed under the terms of a
  17. permission notice identical to this one.
  18.  
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions.
  22.  
  23. 
  24. File: octave,  Node: Commands For Completion,  Next: Commands For History,  Prev: Commands For Text,  Up: Command Line Editing
  25.  
  26. Letting Readline Type For You
  27. -----------------------------
  28.  
  29.    The following commands allow Octave to complete command and variable
  30. names for you.
  31.  
  32. `TAB'
  33.      Attempt to do completion on the text before the cursor.  Octave can
  34.      complete the names of commands and variables.
  35.  
  36. `M-?'
  37.      List the possible completions of the text before the cursor.
  38.  
  39.  - Built-in Variable: completion_append_char
  40.      The value of `completion_append_char' is used as the character to
  41.      append to successful command-line completion attempts.  The default
  42.      value is `" "' (a single space).
  43.  
  44.  - Built-in Function:  completion_matches (HINT)
  45.      Generate possible completions given HINT.
  46.  
  47.      This function is provided for the benefit of programs like Emacs
  48.      which might be controlling Octave and handling user input.  The
  49.      current command number is not incremented when this function is
  50.      called.  This is a feature, not a bug.
  51.  
  52. 
  53. File: octave,  Node: Commands For History,  Next: Customizing the Prompt,  Prev: Commands For Completion,  Up: Command Line Editing
  54.  
  55. Commands For Manipulating The History
  56. -------------------------------------
  57.  
  58.    Octave normally keeps track of the commands you type so that you can
  59. recall previous commands to edit or execute them again.  When you exit
  60. Octave, the most recent commands you have typed, up to the number
  61. specified by the variable `history_size', are saved in a file.  When
  62. Octave starts, it loads an initial list of commands from the file named
  63. by the variable `history_file'.
  64.  
  65.    Here are the commands for simple browsing and searching the history
  66. list.
  67.  
  68. `LFD'
  69. `RET'
  70.      Accept the line regardless of where the cursor is.  If this line is
  71.      non-empty, add it to the history list.  If this line was a history
  72.      line, then restore the history line to its original state.
  73.  
  74. `C-p'
  75.      Move `up' through the history list.
  76.  
  77. `C-n'
  78.      Move `down' through the history list.
  79.  
  80. `M-<'
  81.      Move to the first line in the history.
  82.  
  83. `M->'
  84.      Move to the end of the input history, i.e., the line you are
  85.      entering!
  86.  
  87. `C-r'
  88.      Search backward starting at the current line and moving `up'
  89.      through the history as necessary.  This is an incremental search.
  90.  
  91. `C-s'
  92.      Search forward starting at the current line and moving `down'
  93.      through the history as necessary.
  94.  
  95.    On most terminals, you can also use the arrow keys in place of `C-p'
  96. and `C-n' to move through the history list.
  97.  
  98.    In addition to the keyboard commands for moving through the history
  99. list, Octave provides three functions for viewing, editing, and
  100. re-running chunks of commands from the history list.
  101.  
  102.  - Command: history OPTIONS
  103.      If invoked with no arguments, `history' displays a list of commands
  104.      that you have executed.  Valid options are:
  105.  
  106.     `-w FILE'
  107.           Write the current history to the file FILE.  If the name is
  108.           omitted, use the default history file (normally
  109.           `~/.octave_hist').
  110.  
  111.     `-r FILE'
  112.           Read the file FILE, replacing the current history list with
  113.           its contents.  If the name is omitted, use the default
  114.           history file (normally `~/.octave_hist').
  115.  
  116.     `N'
  117.           Only display the most recent N lines of history.
  118.  
  119.     `-q'
  120.           Don't number the displayed lines of history.  This is useful
  121.           for cutting and pasting commands if you are using the X
  122.           Window System.
  123.  
  124.      For example, to display the five most recent commands that you have
  125.      typed without displaying line numbers, use the command `history -q
  126.      5'.
  127.  
  128.  - Command: edit_history OPTIONS
  129.      If invoked with no arguments, `edit_history' allows you to edit the
  130.      history list using the editor named by the variable `EDITOR'.  The
  131.      commands to be edited are first copied to a temporary file.  When
  132.      you exit the editor, Octave executes the commands that remain in
  133.      the file.  It is often more convenient to use `edit_history' to
  134.      define functions rather than attempting to enter them directly on
  135.      the command line.  By default, the block of commands is executed
  136.      as soon as you exit the editor.  To avoid executing any commands,
  137.      simply delete all the lines from the buffer before exiting the
  138.      editor.
  139.  
  140.      The `edit_history' command takes two optional arguments specifying
  141.      the history numbers of first and last commands to edit.  For
  142.      example, the command
  143.  
  144.           edit_history 13
  145.  
  146.      extracts all the commands from the 13th through the last in the
  147.      history list.  The command
  148.  
  149.           edit_history 13 169
  150.  
  151.      only extracts commands 13 through 169.  Specifying a larger number
  152.      for the first command than the last command reverses the list of
  153.      commands before placing them in the buffer to be edited.  If both
  154.      arguments are omitted, the previous command in the history list is
  155.      used.
  156.  
  157.  - Command: run_history
  158.      Similar to `edit_history', except that the editor is not invoked,
  159.      and the commands are simply executed as they appear in the history
  160.      list.
  161.  
  162.  - Built-in Variable: EDITOR
  163.      A string naming the editor to use with the `edit_history' command.
  164.      If the environment variable `EDITOR' is set when Octave starts, its
  165.      value is used as the default.  Otherwise, `EDITOR' is set to
  166.      `"emacs"'.
  167.  
  168.  - Built-in Variable: history_file
  169.      This variable specifies the name of the file used to store command
  170.      history.  The default value is `"~/.octave_hist"', but may be
  171.      overridden by the environment variable `OCTAVE_HISTFILE'.
  172.  
  173.  - Built-in Variable: history_size
  174.      This variable specifies how many entries to store in the history
  175.      file.  The default value is `1024', but may be overridden by the
  176.      environment variable `OCTAVE_HISTSIZE'.
  177.  
  178.  - Built-in Variable: saving_history
  179.      If the value of `saving_history' is nonzero, command entered on
  180.      the command line are saved in the file specified by the variable
  181.      `history_file'.
  182.  
  183. 
  184. File: octave,  Node: Customizing the Prompt,  Next: Diary and Echo Commands,  Prev: Commands For History,  Up: Command Line Editing
  185.  
  186. Customizing the Prompt
  187. ----------------------
  188.  
  189.    The following variables are available for customizing the appearance
  190. of the command-line prompts.  Octave allows the prompt to be customized
  191. by inserting a number of backslash-escaped special characters that are
  192. decoded as follows:
  193.  
  194. `\t'
  195.      The time.
  196.  
  197. `\d'
  198.      The date.
  199.  
  200. `\n'
  201.      Begins a new line by printing the equivalent of a carriage return
  202.      followed by a line feed.
  203.  
  204. `\s'
  205.      The name of the program (usually just `octave').
  206.  
  207. `\w'
  208.      The current working directory.
  209.  
  210. `\W'
  211.      The basename of the current working directory.
  212.  
  213. `\u'
  214.      The username of the current user.
  215.  
  216. `\h'
  217.      The hostname, up to the first `.'.
  218.  
  219. `\H'
  220.      The hostname.
  221.  
  222. `\#'
  223.      The command number of this command, counting from when Octave
  224.      starts.
  225.  
  226. `\!'
  227.      The history number of this command.  This differs from `\#' by the
  228.      number of commands in the history list when Octave starts.
  229.  
  230. `\$'
  231.      If the effective UID is 0, a `#', otherwise a `$'.
  232.  
  233. `\nnn'
  234.      The character whose character code in octal is NNN.
  235.  
  236. `\\'
  237.      A backslash.
  238.  
  239.  - Built-in Variable: PS1
  240.      The primary prompt string.  When executing interactively, Octave
  241.      displays the primary prompt `PS1' when it is ready to read a
  242.      command.
  243.  
  244.      The default value of `PS1' is `"\s:\#> "'.  To change it, use a
  245.      command like
  246.  
  247.           octave:13> PS1 = "\\u@\\H> "
  248.  
  249.      which will result in the prompt `boris@kremvax> ' for the user
  250.      `boris' logged in on the host `kremvax.kgb.su'.  Note that two
  251.      backslashes are required to enter a backslash into a string.
  252.      *Note Strings::.
  253.  
  254.  - Built-in Variable: PS2
  255.      The secondary prompt string, which is printed when Octave is
  256.      expecting additional input to complete a command.  For example,
  257.      when defining a function over several lines, Octave will print the
  258.      value of `PS1' at the beginning of each line after the first.  The
  259.      default value of `PS2' is `"> "'.
  260.  
  261.  - Built-in Variable: PS4
  262.      If Octave is invoked with the `--echo-input' option, the value of
  263.      `PS4' is printed before each line of input that is echoed.  The
  264.      default value of `PS4' is `"+ "'.  *Note Invoking Octave::, for a
  265.      description of `--echo-input'.
  266.  
  267. 
  268. File: octave,  Node: Diary and Echo Commands,  Prev: Customizing the Prompt,  Up: Command Line Editing
  269.  
  270. Diary and Echo Commands
  271. -----------------------
  272.  
  273.    Octave's diary feature allows you to keep a log of all or part of an
  274. interactive session by recording the input you type and the output that
  275. Octave produces in a separate file.
  276.  
  277.  - Command: diary OPTIONS
  278.      Create a list of all commands *and* the output they produce, mixed
  279.      together just as you see them on your terminal.  Valid options are:
  280.  
  281.     `on'
  282.           Start recording your session in a file called `diary' in your
  283.           current working directory.
  284.  
  285.     `off'
  286.           Stop recording your session in the diary file.
  287.  
  288.     `FILE'
  289.           Record your session in the file named FILE.
  290.  
  291.      Without any arguments, `diary' toggles the current diary state.
  292.  
  293.    Sometimes it is useful to see the commands in a function or script as
  294. they are being evaluated.  This can be especially helpful for debugging
  295. some kinds of problems.
  296.  
  297.  - Command: echo OPTIONS
  298.      Control whether commands are displayed as they are executed.  Valid
  299.      options are:
  300.  
  301.     `on'
  302.           Enable echoing of commands as they are executed in script
  303.           files.
  304.  
  305.     `off'
  306.           Disable echoing of commands as they are executed in script
  307.           files.
  308.  
  309.     `on all'
  310.           Enable echoing of commands as they are executed in script
  311.           files and functions.
  312.  
  313.     `off all'
  314.           Disable echoing of commands as they are executed in script
  315.           files and functions.
  316.  
  317.      If invoked without any arguments, `echo' toggles the current echo
  318.      state.
  319.  
  320.  - Built-in Variable: echo_executing_commands
  321.      This variable is may also be used to control the echo state.  It
  322.      may be the sum of the following values:
  323.  
  324.     1
  325.           Echo commands read from script files.
  326.  
  327.     2
  328.           Echo commands from functions.
  329.  
  330.     4
  331.           Echo commands read from command line.
  332.  
  333.      More than one state can be active at once.  For example, a value
  334.      of 3 is equivalent to the command `echo on all'.
  335.  
  336.      The value of `echo_executing_commands' is set by the `echo'
  337.      command and the command line option `--echo-input'.
  338.  
  339. 
  340. File: octave,  Node: Errors,  Next: Executable Octave Programs,  Prev: Command Line Editing,  Up: Getting Started
  341.  
  342. How Octave Reports Errors
  343. =========================
  344.  
  345.    Octave reports two kinds of errors for invalid programs.
  346.  
  347.    A "parse error" occurs if Octave cannot understand something you
  348. have typed.  For example, if you misspell a keyword,
  349.  
  350.      octave:13> functon y = f (x) y = x^2; endfunction
  351.  
  352. Octave will respond immediately with a message like this:
  353.  
  354.      parse error:
  355.      
  356.        functon y = f (x) y = x^2; endfunction
  357.                ^
  358.  
  359. For most parse errors, Octave uses a caret (`^') to mark the point on
  360. the line where it was unable to make sense of your input.  In this
  361. case, Octave generated an error message because the keyword `function'
  362. was misspelled.  Instead of seeing `function f', Octave saw two
  363. consecutive variable names, which is invalid in this context.  It
  364. marked the error at the `y' because the first name by itself was
  365. accepted as valid input.
  366.  
  367.    Another class of error message occurs at evaluation time.  These
  368. errors are called "run-time errors", or sometimes "evaluation errors"
  369. because they occur when your program is being "run", or "evaluated".
  370. For example, if after correcting the mistake in the previous function
  371. definition, you type
  372.  
  373.      octave:13> f ()
  374.  
  375. Octave will respond with
  376.  
  377.      error: `x' undefined near line 1 column 24
  378.      error: evaluating expression near line 1, column 24
  379.      error: evaluating assignment expression near line 1, column 22
  380.      error: called from `f'
  381.  
  382.    This error message has several parts, and gives you quite a bit of
  383. information to help you locate the source of the error.  The messages
  384. are generated from the point of the innermost error, and provide a
  385. traceback of enclosing expressions and function calls.
  386.  
  387.    In the example above, the first line indicates that a variable named
  388. `x' was found to be undefined near line 1 and column 24 of some
  389. function or expression.  For errors occurring within functions, lines
  390. from the beginning of the file containing the function definition.  For
  391. errors occurring at the top level, the line number indicates the input
  392. line number, which is usually displayed in the prompt string.
  393.  
  394.    The second and third lines in the example indicate that the error
  395. occurred within an assignment expression, and the last line of the error
  396. message indicates that the error occurred within the function `f'.  If
  397. the function `f' had been called from another function, for example,
  398. `g', the list of errors would have ended with one more line:
  399.  
  400.      error: called from `g'
  401.  
  402.    These lists of function calls usually make it fairly easy to trace
  403. the path your program took before the error occurred, and to correct the
  404. error before trying again.
  405.  
  406. 
  407. File: octave,  Node: Executable Octave Programs,  Next: Comments,  Prev: Errors,  Up: Getting Started
  408.  
  409. Executable Octave Programs
  410. ==========================
  411.  
  412.    Once you have learned Octave, you may want to write self-contained
  413. Octave scripts, using the `#!' script mechanism.  You can do this on
  414. GNU systems and on many Unix systems (1)
  415.  
  416.    For example, you could create a text file named `hello', containing
  417. the following lines:
  418.  
  419.      #! OCTAVE-INTERPRETER-NAME -qf
  420.      # a sample Octave program
  421.      printf ("Hello, world!\n");
  422.  
  423. (where OCTAVE-INTERPRETER-NAME should be replaced with the full file
  424. name for your Octave binary).  After making this file executable (with
  425. the `chmod' command), you can simply type:
  426.  
  427.      hello
  428.  
  429. at the shell, and the system will arrange to run Octave as if you had
  430. typed:
  431.  
  432.      octave hello
  433.  
  434.    The line beginning with `#!' lists the full file name of an
  435. interpreter to be run, and an optional initial command line argument to
  436. pass to that interpreter.  The operating system then runs the
  437. interpreter with the given argument and the full argument list of the
  438. executed program.  The first argument in the list is the full file name
  439. of the Octave program. The rest of the argument list will either be
  440. options to Octave, or data files, or both.  The `-qf' option is usually
  441. specified in stand-alone Octave programs to prevent them from printing
  442. the normal startup message, and to keep them from behaving differently
  443. depending on the contents of a particular user's `~/.octaverc' file.
  444. *Note Invoking Octave::.  Note that some operating systems may place a
  445. limit on the number of characters that are recognized after `#!'.
  446.  
  447.    Self-contained Octave scripts are useful when you want to write a
  448. program which users can invoke without knowing that the program is
  449. written in the Octave language.
  450.  
  451.    If you invoke an executable Octave script with command line
  452. arguments, the arguments are available in the built-in variable `argv'.
  453. *Note Command Line Options::.  For example, the following program will
  454. reproduce the command line that is used to execute it.
  455.  
  456.      #! /bin/octave -qf
  457.      printf ("%s", program_name);
  458.      for i = 1:nargin
  459.        printf (" %s", argv(i,:));
  460.      endfor
  461.      printf ("\n");
  462.  
  463.    ---------- Footnotes ----------
  464.  
  465.    (1)  The `#!' mechanism works on Unix systems derived from Berkeley
  466. Unix, System V Release 4, and some System V Release 3 systems.
  467.  
  468. 
  469. File: octave,  Node: Comments,  Prev: Executable Octave Programs,  Up: Getting Started
  470.  
  471. Comments in Octave Programs
  472. ===========================
  473.  
  474.    A "comment" is some text that is included in a program for the sake
  475. of human readers, and that is not really part of the program.  Comments
  476. can explain what the program does, and how it works.  Nearly all
  477. programming languages have provisions for comments, because programs are
  478. typically hard to understand without them.
  479.  
  480.    In the Octave language, a comment starts with either the sharp sign
  481. character, `#', or the percent symbol `%' and continues to the end of
  482. the line.  The Octave interpreter ignores the rest of a line following
  483. a sharp sign or percent symbol.  For example, we could have put the
  484. following into the function `f':
  485.  
  486.      function xdot = f (x, t)
  487.      
  488.      # usage: f (x, t)
  489.      #
  490.      # This function defines the right hand
  491.      # side functions for a set of nonlinear
  492.      # differential equations.
  493.      
  494.        r = 0.25;
  495.        ...
  496.      endfunction
  497.  
  498.    The `help' command (*note Getting Help::.) is able to find the first
  499. block of comments in a function (even those that are composed directly
  500. on the command line).  This means that users of Octave can use the same
  501. commands to get help for built-in functions, and for functions that you
  502. have defined.  For example, after defining the function `f' above, the
  503. command `help f' produces the output
  504.  
  505.       usage: f (x, t)
  506.      
  507.       This function defines the right hand
  508.       side functions for a set of nonlinear
  509.       differential equations.
  510.  
  511.    Although it is possible to put comment lines into keyboard-composed
  512. throw-away Octave programs, it usually isn't very useful, because the
  513. purpose of a comment is to help you or another person understand the
  514. program at a later time.
  515.  
  516. 
  517. File: octave,  Node: Data Types,  Next: Numeric Data Types,  Prev: Getting Started,  Up: Top
  518.  
  519. Data Types
  520. **********
  521.  
  522.    All versions of Octave include a number of built-in data types,
  523. including real and complex scalars and matrices, character strings, and
  524. a data structure type.
  525.  
  526.    It is also possible to define new specialized data types by writing a
  527. small amount of C++ code.  On some systems, new data types can be loaded
  528. dynamically while Octave is running, so it is not necessary to recompile
  529. all of Octave just to add a new type.  *Note Dynamically Linked
  530. Functions:: for more information about Octave's dynamic linking
  531. capabilities.  *Note User-defined Data Types:: describes what you must
  532. do to define a new data type for Octave.
  533.  
  534. * Menu:
  535.  
  536. * Built-in Data Types::
  537. * User-defined Data Types::
  538. * Object Sizes::
  539.  
  540. 
  541. File: octave,  Node: Built-in Data Types,  Next: User-defined Data Types,  Prev: Data Types,  Up: Data Types
  542.  
  543. Built-in Data Types
  544. ===================
  545.  
  546.    The standard built-in data types are real and complex scalars and
  547. matrices, ranges, character strings, and a data structure type.
  548. Additional built-in data types may be added in future versions.  If you
  549. need a specialized data type that is not currently provided as a
  550. built-in type, you are encouraged to write your own user-defined data
  551. type and contribute it for distribution in a future release of Octave.
  552.  
  553. * Menu:
  554.  
  555. * Numeric Objects::
  556. * String Objects::
  557. * Data Structure Objects::
  558.  
  559. 
  560. File: octave,  Node: Numeric Objects,  Next: String Objects,  Prev: Built-in Data Types,  Up: Built-in Data Types
  561.  
  562. Numeric Objects
  563. ---------------
  564.  
  565.    Octave's built-in numeric objects include real and complex scalars
  566. and matrices.  All built-in numeric data is currently stored as double
  567. precision numbers.  On systems that use the IEEE floating point format,
  568. values in the range of approximately  2.2251e-308 to 1.7977e+308  can
  569. be stored, and the relative precision is approximately  2.2204e-16.
  570. The exact values are given by the variables `realmin', `realmax', and
  571. `eps', respectively.
  572.  
  573.    Matrix objects can be of any size, and can be dynamically reshaped
  574. and resized.  It is easy to extract individual rows, columns, or
  575. submatrices is using a variety of powerful indexing features.  *Note
  576. Index Expressions::.
  577.  
  578.    *Note Numeric Data Types::, for more information.
  579.  
  580. 
  581. File: octave,  Node: String Objects,  Next: Data Structure Objects,  Prev: Numeric Objects,  Up: Built-in Data Types
  582.  
  583. String Objects
  584. --------------
  585.  
  586.    A character string in Octave consists of a sequence of characters
  587. enclosed in either double-quote or single-quote marks.  Internally,
  588. Octave currently stores strings as matrices of characters.  All the
  589. indexing operations that work for matrix objects also work for strings.
  590.  
  591.    *Note Strings::, for more information.
  592.  
  593. 
  594. File: octave,  Node: Data Structure Objects,  Prev: String Objects,  Up: Built-in Data Types
  595.  
  596. Data Structure Objects
  597. ----------------------
  598.  
  599.    Octave's data structure type can help you to organize related
  600. objects of different types.  The current implementation uses an
  601. associative array with indices limited to strings, but the syntax is
  602. more like C-style structures.
  603.  
  604.    *Note Data Structures::, for more information.
  605.  
  606. 
  607. File: octave,  Node: User-defined Data Types,  Next: Object Sizes,  Prev: Built-in Data Types,  Up: Data Types
  608.  
  609. User-defined Data Types
  610. =======================
  611.  
  612.    Someday I hope to expand this to include a complete description of
  613. Octave's mechanism for managing user-defined data types.  Until this
  614. feature is documented here, you will have to make do by reading the code
  615. in the `ov.h', `ops.h', and related files from Octave's `src' directory.
  616.  
  617. 
  618. File: octave,  Node: Object Sizes,  Prev: User-defined Data Types,  Up: Data Types
  619.  
  620. Object Sizes
  621. ============
  622.  
  623.    The following functions allow you to determine the size of a
  624. variable or expression.  These functions are defined for all objects.
  625. They return -1 when the operation doesn't make sense.  For example,
  626. Octave's data structure type doesn't have rows or columns, so the
  627. `rows' and `columns' functions return -1 for structure arguments.
  628.  
  629.  - Function File:  columns (A)
  630.      Return the number of columns of A.
  631.  
  632.  - Function File:  rows (A)
  633.      Return the number of rows of A.
  634.  
  635.  - Function File:  length (A)
  636.      Return the number of rows of A or the number of columns of A,
  637.      whichever is larger.
  638.  
  639.  - Function File:  size (A, N)
  640.      Return the number rows and columns of A.
  641.  
  642.      With one input argument and one output argument, the result is
  643.      returned in a 2 element row vector.  If there are two output
  644.      arguments, the number of rows is assigned to the first, and the
  645.      number of columns to the second.  For example,
  646.  
  647.           size ([1, 2; 3, 4; 5, 6])
  648.                => [ 3, 2 ]
  649.           
  650.           [nr, nc] = size ([1, 2; 3, 4; 5, 6])
  651.                => nr = 3
  652.                => nc = 2
  653.  
  654.      If given a second argument of either 1 or 2, `size' will return
  655.      only the row or column dimension.  For example
  656.  
  657.           size ([1, 2; 3, 4; 5, 6], 2)
  658.                => 2
  659.  
  660.      returns the number of columns in the given matrix.
  661.  
  662.  - Function File:  isempty (A)
  663.      Return 1 if A is an empty matrix (either the number of rows, or
  664.      the number of columns, or both are zero).  Otherwise, return 0.
  665.  
  666. 
  667. File: octave,  Node: Numeric Data Types,  Next: Strings,  Prev: Data Types,  Up: Top
  668.  
  669. Numeric Data Types
  670. ******************
  671.  
  672.    A "numeric constant" may be a scalar, a vector, or a matrix, and it
  673. may contain complex values.
  674.  
  675.    The simplest form of a numeric constant, a scalar, is a single number
  676. that can be an integer, a decimal fraction, a number in scientific
  677. (exponential) notation, or a complex number.  Note that all numeric
  678. constants are represented within Octave in double-precision floating
  679. point format (complex constants are stored as pairs of double-precision
  680. floating point values).  Here are some examples of real-valued numeric
  681. constants, which all have the same value:
  682.  
  683.      105
  684.      1.05e+2
  685.      1050e-1
  686.  
  687.    To specify complex constants, you can write an expression of the form
  688.  
  689.      3 + 4i
  690.      3.0 + 4.0i
  691.      0.3e1 + 40e-1i
  692.  
  693.    all of which are equivalent.  The letter `i' in the previous example
  694. stands for the pure imaginary constant, defined as   `sqrt (-1)'.
  695.  
  696.    For Octave to recognize a value as the imaginary part of a complex
  697. constant, a space must not appear between the number and the `i'.  If
  698. it does, Octave will print an error message, like this:
  699.  
  700.      octave:13> 3 + 4 i
  701.      
  702.      parse error:
  703.      
  704.        3 + 4 i
  705.              ^
  706.  
  707.    You may also use `j', `I', or `J' in place of the `i' above.  All
  708. four forms are equivalent.
  709.  
  710. * Menu:
  711.  
  712. * Matrices::
  713. * Ranges::
  714. * Predicates for Numeric Objects::
  715.  
  716. 
  717. File: octave,  Node: Matrices,  Next: Ranges,  Prev: Numeric Data Types,  Up: Numeric Data Types
  718.  
  719. Matrices
  720. ========
  721.  
  722.    It is easy to define a matrix of values in Octave.  The size of the
  723. matrix is determined automatically, so it is not necessary to explicitly
  724. state the dimensions.  The expression
  725.  
  726.      a = [1, 2; 3, 4]
  727.  
  728. results in the matrix
  729.  
  730.  
  731.              /      \
  732.              | 1  2 |
  733.        a  =  |      |
  734.              | 3  4 |
  735.              \      /
  736.  
  737.    Elements of a matrix may be arbitrary expressions, provided that the
  738. dimensions all make sense when combining the various pieces.  For
  739. example, given the above matrix, the expression
  740.  
  741.      [ a, a ]
  742.  
  743. produces the matrix
  744.  
  745.      ans =
  746.      
  747.        1  2  1  2
  748.        3  4  3  4
  749.  
  750. but the expression
  751.  
  752.      [ a, 1 ]
  753.  
  754. produces the error
  755.  
  756.      error: number of rows must match near line 13, column 6
  757.  
  758. (assuming that this expression was entered as the first thing on line
  759. 13, of course).
  760.  
  761.    Inside the square brackets that delimit a matrix expression, Octave
  762. looks at the surrounding context to determine whether spaces and newline
  763. characters should be converted into element and row separators, or
  764. simply ignored, so commands like
  765.  
  766.      [ linspace (1, 2) ]
  767.  
  768. and
  769.  
  770.      a = [ 1 2
  771.            3 4 ]
  772.  
  773. will work.  However, some possible sources of confusion remain.  For
  774. example, in the expression
  775.  
  776.      [ 1 - 1 ]
  777.  
  778. the `-' is treated as a binary operator and the result is the scalar 0,
  779. but in the expression
  780.  
  781.      [ 1 -1 ]
  782.  
  783. the `-' is treated as a unary operator and the result is the vector `[
  784. 1, -1 ]'.
  785.  
  786.    Given `a = 1', the expression
  787.  
  788.      [ 1 a' ]
  789.  
  790. results in the single quote character `'' being treated as a transpose
  791. operator and the result is the vector `[ 1, 1 ]', but the expression
  792.  
  793.      [ 1 a ' ]
  794.  
  795. produces the error message
  796.  
  797.      error: unterminated string constant
  798.  
  799. because to not do so would make it impossible to correctly parse the
  800. valid expression
  801.  
  802.      [ a 'foo' ]
  803.  
  804.    For clarity, it is probably best to always use commas and semicolons
  805. to separate matrix elements and rows.  It is possible to enforce this
  806. style by setting the built-in variable `whitespace_in_literal_matrix' to
  807. `"ignore"'.
  808.  
  809.  - Built-in Variable: whitespace_in_literal_matrix
  810.      This variable allows some control over how Octave decides to
  811.      convert spaces to commas and semicolons in matrix expressions like
  812.      `[m (1)]' or
  813.  
  814.           [ 1, 2,
  815.             3, 4 ]
  816.  
  817.      If the value of `whitespace_in_literal_matrix' is `"ignore"',
  818.      Octave will never insert a comma or a semicolon in a literal matrix
  819.      list.  For example, the expression `[1 2]' will result in an error
  820.      instead of being treated the same as `[1, 2]', and the expression
  821.  
  822.           [ 1, 2,
  823.             3, 4 ]
  824.  
  825.      will result in the vector `[ 1, 2, 3, 4 ]' instead of a matrix.
  826.  
  827.      If the value of `whitespace_in_literal_matrix' is `"traditional"',
  828.      Octave will convert spaces to a comma between identifiers and `('.
  829.      For example, given the matrix
  830.  
  831.           m = [3 2]
  832.  
  833.      the expression
  834.  
  835.           [m (1)]
  836.  
  837.      will be parsed as
  838.  
  839.           [m, (1)]
  840.  
  841.      and will result in
  842.  
  843.           [3 2 1]
  844.  
  845.      and the expression
  846.  
  847.           [ 1, 2,
  848.             3, 4 ]
  849.  
  850.      will result in a matrix because the newline character is converted
  851.      to a semicolon (row separator) even though there is a comma at the
  852.      end of the first line (trailing commas or semicolons are ignored).
  853.      This is apparently how MATLAB behaves.
  854.  
  855.      Any other value for `whitespace_in_literal_matrix' results in
  856.      behavior that is the same as traditional, except that Octave does
  857.      not convert spaces to a comma between identifiers and `('.  For
  858.      example, the expression
  859.  
  860.           [m (1)]
  861.  
  862.      will produce `3'.  This is the way Octave has always behaved.
  863.  
  864.    When you type a matrix or the name of a variable whose value is a
  865. matrix, Octave responds by printing the matrix in with neatly aligned
  866. rows and columns.  If the rows of the matrix are too large to fit on the
  867. screen, Octave splits the matrix and displays a header before each
  868. section to indicate which columns are being displayed.  You can use the
  869. following variables to control the format of the output.
  870.  
  871.  - Built-in Variable: output_max_field_width
  872.      This variable specifies the maximum width of a numeric output
  873.      field.  The default value is 10.
  874.  
  875.  - Built-in Variable: output_precision
  876.      This variable specifies the minimum number of significant figures
  877.      to display for numeric output.  The default value is 5.
  878.  
  879.    It is possible to achieve a wide range of output styles by using
  880. different values of `output_precision' and `output_max_field_width'.
  881. Reasonable combinations can be set using the `format' function.  *Note
  882. Basic Input and Output::.
  883.  
  884.  - Built-in Variable: split_long_rows
  885.      For large matrices, Octave may not be able to display all the
  886.      columns of a given row on one line of your screen.  This can
  887.      result in missing information or output that is nearly impossible
  888.      to decipher, depending on whether your terminal truncates or wraps
  889.      long lines.
  890.  
  891.      If the value of `split_long_rows' is nonzero, Octave will display
  892.      the matrix in a series of smaller pieces, each of which can fit
  893.      within the limits of your terminal width.  Each set of rows is
  894.      labeled so that you can easily see which columns are currently
  895.      being displayed.  For example:
  896.  
  897.           octave:13> rand (2,10)
  898.           ans =
  899.           
  900.            Columns 1 through 6:
  901.           
  902.             0.75883  0.93290  0.40064  0.43818  0.94958  0.16467
  903.             0.75697  0.51942  0.40031  0.61784  0.92309  0.40201
  904.           
  905.            Columns 7 through 10:
  906.           
  907.             0.90174  0.11854  0.72313  0.73326
  908.             0.44672  0.94303  0.56564  0.82150
  909.  
  910.      The default value of `split_long_rows' is nonzero.
  911.  
  912.    Octave automatically switches to scientific notation when values
  913. become very large or very small.  This guarantees that you will see
  914. several significant figures for every value in a matrix.  If you would
  915. prefer to see all values in a matrix printed in a fixed point format,
  916. you can set the built-in variable `fixed_point_format' to a nonzero
  917. value.  But doing so is not recommended, because it can produce output
  918. that can easily be misinterpreted.
  919.  
  920.  - Built-in Variable: fixed_point_format
  921.      If the value of this variable is nonzero, Octave will scale all
  922.      values in a matrix so that the largest may be written with one
  923.      leading digit.  The scaling factor is printed on the first line of
  924.      output.  For example,
  925.  
  926.           octave:1> logspace (1, 7, 5)'
  927.           ans =
  928.           
  929.             1.0e+07  *
  930.           
  931.             0.00000
  932.             0.00003
  933.             0.00100
  934.             0.03162
  935.             1.00000
  936.  
  937.      Notice that first value appears to be zero when it is actually 1.
  938.      For this reason, you should be careful when setting
  939.      `fixed_point_format' to a nonzero value.
  940.  
  941.      The default value of `fixed_point_format' is 0.
  942.  
  943. * Menu:
  944.  
  945. * Empty Matrices::
  946.  
  947. 
  948. File: octave,  Node: Empty Matrices,  Prev: Matrices,  Up: Matrices
  949.  
  950. Empty Matrices
  951. --------------
  952.  
  953.    A matrix may have one or both dimensions zero, and operations on
  954. empty matrices are handled as described by Carl de Boor in `An Empty
  955. Exercise', SIGNUM, Volume 25, pages 2-6, 1990 and C. N. Nett and W. M.
  956. Haddad, in `A System-Theoretic Appropriate Realization of the Empty
  957. Matrix Concept', IEEE Transactions on Automatic Control, Volume 38,
  958. Number 5, May 1993.  Briefly, given a scalar S, an M by N matrix
  959. `M(mxn)', and an M by N empty matrix `[](mxn)' (with either one or both
  960. dimensions equal to zero), the following are true:
  961.  
  962.      s * [](mxn) = [](mxn) * s = [](mxn)
  963.      
  964.          [](mxn) + [](mxn) = [](mxn)
  965.      
  966.          [](0xm) *  M(mxn) = [](0xn)
  967.      
  968.           M(mxn) * [](nx0) = [](mx0)
  969.      
  970.          [](mx0) * [](0xn) =  0(mxn)
  971.  
  972.    By default, dimensions of the empty matrix are printed along with the
  973. empty matrix symbol, `[]'.  The built-in variable
  974. `print_empty_dimensions' controls this behavior.
  975.  
  976.  - Built-in Variable: print_empty_dimensions
  977.      If the value of `print_empty_dimensions' is nonzero, the
  978.      dimensions of empty matrices are printed along with the empty
  979.      matrix symbol, `[]'.  For example, the expression
  980.  
  981.           zeros (3, 0)
  982.  
  983.      will print
  984.  
  985.           ans = [](3x0)
  986.  
  987.    Empty matrices may also be used in assignment statements as a
  988. convenient way to delete rows or columns of matrices.  *Note Assignment
  989. Expressions: Assignment Ops.
  990.  
  991.    Octave will normally issue a warning if it finds an empty matrix in
  992. the list of elements that make up another matrix.  You can use the
  993. variable `empty_list_elements_ok' to suppress the warning or to treat
  994. it as an error.
  995.  
  996.  - Built-in Variable: empty_list_elements_ok
  997.      This variable controls whether Octave ignores empty matrices in a
  998.      matrix list.
  999.  
  1000.      For example, if the value of `empty_list_elements_ok' is nonzero,
  1001.      Octave will ignore the empty matrices in the expression
  1002.  
  1003.           a = [1, [], 3, [], 5]
  1004.  
  1005.      and the variable `a' will be assigned the value `[ 1, 3, 5 ]'.
  1006.  
  1007.      The default value is `"warn"'.
  1008.  
  1009.    When Octave parses a matrix expression, it examines the elements of
  1010. the list to determine whether they are all constants.  If they are, it
  1011. replaces the list with a single matrix constant.
  1012.  
  1013.  - Built-in Variable: propagate_empty_matrices
  1014.      If the value of `propagate_empty_matrices' is nonzero, functions
  1015.      like `inverse' and `svd' will return an empty matrix if they are
  1016.      given one as an argument.  The default value is 1.
  1017.  
  1018. 
  1019. File: octave,  Node: Ranges,  Next: Predicates for Numeric Objects,  Prev: Matrices,  Up: Numeric Data Types
  1020.  
  1021. Ranges
  1022. ======
  1023.  
  1024.    A "range" is a convenient way to write a row vector with evenly
  1025. spaced elements.  A range expression is defined by the value of the
  1026. first element in the range, an optional value for the increment between
  1027. elements, and a maximum value which the elements of the range will not
  1028. exceed.  The base, increment, and limit are separated by colons (the
  1029. `:' character) and may contain any arithmetic expressions and function
  1030. calls.  If the increment is omitted, it is assumed to be 1.  For
  1031. example, the range
  1032.  
  1033.      1 : 5
  1034.  
  1035. defines the set of values `[ 1, 2, 3, 4, 5 ]', and the range
  1036.  
  1037.      1 : 3 : 5
  1038.  
  1039. defines the set of values `[ 1, 4 ]'.
  1040.  
  1041.    Although a range constant specifies a row vector, Octave does *not*
  1042. convert range constants to vectors unless it is necessary to do so.
  1043. This allows you to write a constant like `1 : 10000' without using
  1044. 80,000 bytes of storage on a typical 32-bit workstation.
  1045.  
  1046.    Note that the upper (or lower, if the increment is negative) bound on
  1047. the range is not always included in the set of values, and that ranges
  1048. defined by floating point values can produce surprising results because
  1049. Octave uses floating point arithmetic to compute the values in the
  1050. range.  If it is important to include the endpoints of a range and the
  1051. number of elements is known, you should use the `linspace' function
  1052. instead (*note Special Utility Matrices::.).
  1053.  
  1054.    When Octave parses a range expression, it examines the elements of
  1055. the expression to determine whether they are all constants.  If they
  1056. are, it replaces the range expression with a single range constant.
  1057.  
  1058. 
  1059. File: octave,  Node: Predicates for Numeric Objects,  Prev: Ranges,  Up: Numeric Data Types
  1060.  
  1061. Predicates for Numeric Objects
  1062. ==============================
  1063.  
  1064.  - Function File:  is_matrix (A)
  1065.      Return 1 if A is a matrix.  Otherwise, return 0.
  1066.  
  1067.  - Function File:  is_vector (A)
  1068.      Return 1 if A is a vector.  Otherwise, return 0.
  1069.  
  1070.  - Function File:  is_scalar (A)
  1071.      Return 1 if A is a scalar.  Otherwise, return 0.
  1072.  
  1073.  - Function File:  is_square (X)
  1074.      If X is a square matrix, then return the dimension of X.
  1075.      Otherwise, return 0.
  1076.  
  1077.  - Function File:  is_symmetric (X, TOL)
  1078.      If X is symmetric within the tolerance specified by TOL, then
  1079.      return the dimension of X.  Otherwise, return 0.  If TOL is
  1080.      omitted, use a tolerance equal to the machine precision.
  1081.  
  1082. 
  1083. File: octave,  Node: Strings,  Next: Data Structures,  Prev: Numeric Data Types,  Up: Top
  1084.  
  1085. Strings
  1086. *******
  1087.  
  1088.    A "string constant" consists of a sequence of characters enclosed in
  1089. either double-quote or single-quote marks.  For example, both of the
  1090. following expressions
  1091.  
  1092.      "parrot"
  1093.      'parrot'
  1094.  
  1095. represent the string whose contents are `parrot'.  Strings in Octave
  1096. can be of any length.
  1097.  
  1098.    Since the single-quote mark is also used for the transpose operator
  1099. (*note Arithmetic Ops::.) but double-quote marks have no other purpose
  1100. in Octave, it is best to use double-quote marks to denote strings.
  1101.  
  1102.    Some characters cannot be included literally in a string constant.
  1103. You represent them instead with "escape sequences", which are character
  1104. sequences beginning with a backslash (`\').
  1105.  
  1106.    One use of an escape sequence is to include a double-quote
  1107. (single-quote) character in a string constant that has been defined
  1108. using double-quote (single-quote) marks.  Since a plain double-quote
  1109. would end the string, you must use `\"' to represent a single
  1110. double-quote character as a part of the string.  The backslash character
  1111. itself is another character that cannot be included normally.  You must
  1112. write `\\' to put one backslash in the string.  Thus, the string whose
  1113. contents are the two characters `"\' may be written `"\"\\"' or
  1114. `'"\\''.  Similarly, the string whose contents are the two characters
  1115. `'\' may be written `'\'\\'' or `"'\\"'.
  1116.  
  1117.    Another use of backslash is to represent unprintable characters such
  1118. as newline.  While there is nothing to stop you from writing most of
  1119. these characters directly in a string constant, they may look ugly.
  1120.  
  1121.    Here is a table of all the escape sequences used in Octave.  They are
  1122. the same as those used in the C programming language.
  1123.  
  1124. `\\'
  1125.      Represents a literal backslash, `\'.
  1126.  
  1127. `\"'
  1128.      Represents a literal double-quote character, `"'.
  1129.  
  1130. `\''
  1131.      Represents a literal single-quote character, `''.
  1132.  
  1133. `\a'
  1134.      Represents the "alert" character, control-g, ASCII code 7.
  1135.  
  1136. `\b'
  1137.      Represents a backspace, control-h, ASCII code 8.
  1138.  
  1139. `\f'
  1140.      Represents a formfeed, control-l, ASCII code 12.
  1141.  
  1142. `\n'
  1143.      Represents a newline, control-j, ASCII code 10.
  1144.  
  1145. `\r'
  1146.      Represents a carriage return, control-m, ASCII code 13.
  1147.  
  1148. `\t'
  1149.      Represents a horizontal tab, control-i, ASCII code 9.
  1150.  
  1151. `\v'
  1152.      Represents a vertical tab, control-k, ASCII code 11.
  1153.  
  1154.    Strings may be concatenated using the notation for defining matrices.
  1155. For example, the expression
  1156.  
  1157.      [ "foo" , "bar" , "baz" ]
  1158.  
  1159. produces the string whose contents are `foobarbaz'.  *Note Numeric Data
  1160. Types:: for more information about creating matrices.
  1161.  
  1162. * Menu:
  1163.  
  1164. * Creating Strings::
  1165. * Searching and Replacing::
  1166. * String Conversions::
  1167. * Character Class Functions::
  1168.  
  1169. 
  1170. File: octave,  Node: Creating Strings,  Next: Searching and Replacing,  Prev: Strings,  Up: Strings
  1171.  
  1172. Creating Strings
  1173. ================
  1174.  
  1175.  - Function File:  blanks (N)
  1176.      Return a string of N blanks.
  1177.  
  1178.  - Function File:  int2str (N)
  1179.  - Function File:  num2str (X)
  1180.      Convert a number to a string.  These functions are not very
  1181.      flexible, but are provided for compatibility with MATLAB.  For
  1182.      better control over the results, use `sprintf' (*note Formatted
  1183.      Output::.).
  1184.  
  1185.  - Built-in Function:  setstr (X)
  1186.      Convert a matrix to a string.  Each element of the matrix is
  1187.      converted to the corresponding ASCII character.  For example,
  1188.  
  1189.           setstr ([97, 98, 99])
  1190.                => "abc"
  1191.  
  1192.  - Function File:  strcat (S1, S2, ...)
  1193.      Return a string containing all the arguments concatenated.  For
  1194.      example,
  1195.  
  1196.           s = [ "ab"; "cde" ];
  1197.           strcat (s, s, s)
  1198.                => "ab ab ab "
  1199.                   "cdecdecde"
  1200.  
  1201.  - Built-in Variable: string_fill_char
  1202.      The value of this variable is used to pad all strings in a string
  1203.      matrix to the same length.  It should be a single character.  The
  1204.      default value is `" "' (a single space).  For example,
  1205.  
  1206.           string_fill_char = "X";
  1207.           [ "these"; "are"; "strings" ]
  1208.                => "theseXX"
  1209.                   "areXXXX"
  1210.                   "strings"
  1211.  
  1212.  - Function File:  str2mat (S_1, ..., S_N)
  1213.      Return a matrix containing the strings S_1, ..., S_N as its rows.
  1214.      Each string is padded with blanks in order to form a valid matrix.
  1215.  
  1216.      *Note:* This function is modelled after MATLAB.  In Octave, you
  1217.      can create a matrix of strings by `[S_1; ...; S_N]' even if the
  1218.      strings are not all the same length.
  1219.  
  1220.  - Built-in Function:  isstr (A)
  1221.      Return 1 if A is a string.  Otherwise, return 0.
  1222.  
  1223. 
  1224. File: octave,  Node: Searching and Replacing,  Next: String Conversions,  Prev: Creating Strings,  Up: Strings
  1225.  
  1226. Searching and Replacing
  1227. =======================
  1228.  
  1229.  - Function File:  deblank (S)
  1230.      Removes the trailing blanks from the string S.
  1231.  
  1232.  - Function File:  findstr (S, T, OVERLAP)
  1233.      Return the vector of all positions in the longer of the two strings
  1234.      S and T where an occurrence of the shorter of the two starts.  If
  1235.      the optional argument OVERLAP is nonzero, the returned vector can
  1236.      include overlapping positions (this is the default).  For example,
  1237.  
  1238.           findstr ("ababab", "a")
  1239.                => [ 1, 3, 5 ]
  1240.           findstr ("abababa", "aba", 0)
  1241.                => [ 1, 5 ]
  1242.  
  1243.  - Function File:  index (S, T)
  1244.      Return the position of the first occurrence of the string T in the
  1245.      string S, or 0 if no occurrence is found.  For example,
  1246.  
  1247.           index ("Teststring", "t")
  1248.                => 4
  1249.  
  1250.      *Note:*  This function does not work for arrays of strings.
  1251.  
  1252.  - Function File:  rindex (S, T)
  1253.      Return the position of the last occurrence of the string T in the
  1254.      string S, or 0 if no occurrence is found.  For example,
  1255.  
  1256.           rindex ("Teststring", "t")
  1257.                => 6
  1258.  
  1259.      *Note:*  This function does not work for arrays of strings.
  1260.  
  1261.  - Function File:  split (S, T)
  1262.      Divides the string S into pieces separated by T, returning the
  1263.      result in a string array (padded with blanks to form a valid
  1264.      matrix).  For example,
  1265.  
  1266.           split ("Test string", "t")
  1267.                => "Tes "
  1268.                   " s  "
  1269.                   "ring"
  1270.  
  1271.  - Function File:  strcmp (S1, S2)
  1272.      Compares two strings, returning 1 if they are the same, and 0
  1273.      otherwise.
  1274.  
  1275.      *Note:*  For compatibility with MATLAB, Octave's strcmp function
  1276.      returns 1 if the strings are equal, and 0 otherwise.  This is just
  1277.      the opposite of the corresponding C library function.
  1278.  
  1279.  - Function File:  strrep (S, X, Y)
  1280.      Replaces all occurrences of the substring X of the string S with
  1281.      the string Y.  For example,
  1282.  
  1283.           strrep ("This is a test string", "is", "&%$")
  1284.                => "Th&%$ &%$ a test string"
  1285.  
  1286.  - Function File:  substr (S, BEG, LEN)
  1287.      Return the substring of S which starts at character number BEG and
  1288.      is LEN characters long.  For example,
  1289.  
  1290.           substr ("This is a test string", 6, 9)
  1291.                => "is a test"
  1292.  
  1293.           *Note:* This function is patterned after AWK.  You can get
  1294.           the same result by `S (BEG : (BEG + LEN - 1))'.
  1295.  
  1296. 
  1297. File: octave,  Node: String Conversions,  Next: Character Class Functions,  Prev: Searching and Replacing,  Up: Strings
  1298.  
  1299. String Conversions
  1300. ==================
  1301.  
  1302.  - Function File:  bin2dec (S)
  1303.      Return a decimal number corresponding to the binary number
  1304.      represented as a string of zeros and ones.  For example,
  1305.  
  1306.           bin2dec ("1110")
  1307.                => 14
  1308.  
  1309.  - Function File:  dec2bin (N)
  1310.      Return a binary number corresponding the nonnegative decimal number
  1311.      N, as a string of ones and zeros.  For example,
  1312.  
  1313.           dec2bin (14)
  1314.                => "1110"
  1315.  
  1316.  - Function File:  dec2hex (N)
  1317.      Return the hexadecimal number corresponding to the nonnegative
  1318.      decimal number N, as a string.  For example,
  1319.  
  1320.           dec2hex (2748)
  1321.                => "abc"
  1322.  
  1323.  - Function File:  hex2dec (S)
  1324.      Return the decimal number corresponding to the hexadecimal number
  1325.      stored in the string S.  For example,
  1326.  
  1327.           hex2dec ("12B")
  1328.                => 299
  1329.           hex2dec ("12b")
  1330.                => 299
  1331.  
  1332.  - Function File:  str2num (S)
  1333.      Convert the string S to a number.
  1334.  
  1335.  - Function File:  toascii (S)
  1336.      Return ASCII representation of S in a matrix.  For example,
  1337.  
  1338.           toascii ("ASCII")
  1339.                => [ 65, 83, 67, 73, 73 ]
  1340.  
  1341.  
  1342.  - Function File:  tolower (S)
  1343.      Return a copy of the string S, with each upper-case character
  1344.      replaced by the corresponding lower-case one; nonalphabetic
  1345.      characters are left unchanged.  For example,
  1346.  
  1347.           tolower ("MiXeD cAsE 123")
  1348.                => "mixed case 123"
  1349.  
  1350.  - Function File:  toupper (S)
  1351.      Return a copy of the string S, with each  lower-case character
  1352.      replaced by the corresponding upper-case one; nonalphabetic
  1353.      characters are left unchanged.  For example,
  1354.  
  1355.           toupper ("MiXeD cAsE 123")
  1356.                => "MIXED CASE 123"
  1357.  
  1358.  - Built-in Function:  undo_string_escapes (S)
  1359.      Converts special characters in strings back to their escaped
  1360.      forms.  For example, the expression
  1361.  
  1362.           bell = "\a";
  1363.  
  1364.      assigns the value of the alert character (control-g, ASCII code 7)
  1365.      to the string variable `bell'.  If this string is printed, the
  1366.      system will ring the terminal bell (if it is possible).  This is
  1367.      normally the desired outcome.  However, sometimes it is useful to
  1368.      be able to print the original representation of the string, with
  1369.      the special characters replaced by their escape sequences.  For
  1370.      example,
  1371.  
  1372.           octave:13> undo_string_escapes (bell)
  1373.           ans = \a
  1374.  
  1375.      replaces the unprintable alert character with its printable
  1376.      representation.
  1377.  
  1378.  - Built-in Variable: implicit_num_to_str_ok
  1379.      If the value of `implicit_num_to_str_ok' is nonzero, implicit
  1380.      conversions of numbers to their ASCII character equivalents are
  1381.      allowed when strings are constructed using a mixture of strings and
  1382.      numbers in matrix notation.  Otherwise, an error message is
  1383.      printed and control is returned to the top level. The default
  1384.      value is 0.  For example,
  1385.  
  1386.           [ "f", 111, 111 ]
  1387.                => "foo"
  1388.  
  1389.  - Built-in Variable: implicit_str_to_num_ok
  1390.      If the value of `implicit_str_to_num_ok' is nonzero, implicit
  1391.      conversions of strings to their numeric ASCII equivalents are
  1392.      allowed.  Otherwise, an error message is printed and control is
  1393.      returned to the top level.  The default value is 0.
  1394.  
  1395. 
  1396. File: octave,  Node: Character Class Functions,  Prev: String Conversions,  Up: Strings
  1397.  
  1398. Character Class Functions
  1399. =========================
  1400.  
  1401.    Octave also provides the following character class test functions
  1402. patterned after the functions in the standard C library.  They all
  1403. operate on string arrays and return matrices of zeros and ones.
  1404. Elements that are nonzero indicate that the condition was true for the
  1405. corresponding character in the string array.  For example,
  1406.  
  1407.      isalpha ("!Q@WERT^Y&")
  1408.           => [ 0, 1, 0, 1, 1, 1, 1, 0, 1, 0 ]
  1409.  
  1410.  - Mapping Function:  isalnum (S)
  1411.      Return 1 for characters that are letters or digits (`isalpha (A)'
  1412.      or `isdigit ()' is true).
  1413.  
  1414.  - Mapping Function:  isalpha (S)
  1415.      Return true for characters that are letters (`isupper (A)' or
  1416.      `islower ()' is true).
  1417.  
  1418.  - Mapping Function:  isascii (S)
  1419.      Return 1 for characters that are ASCII (in the range 0 to 127
  1420.      decimal).
  1421.  
  1422.  - Mapping Function:  iscntrl (S)
  1423.      Return 1 for control characters.
  1424.  
  1425.  - Mapping Function:  isdigit (S)
  1426.      Return 1 for characters that are decimal digits.
  1427.  
  1428.  - Mapping Function:  isgraph (S)
  1429.      Return 1 for printable characters (but not the space character).
  1430.  
  1431.  - Mapping Function:  islower (S)
  1432.      Return 1 for characters that are lower case letters.
  1433.  
  1434.  - Mapping Function:  isprint (S)
  1435.      Return 1 for printable characters (including the space character).
  1436.  
  1437.  - Mapping Function:  ispunct (S)
  1438.      Return 1 for punctuation characters.
  1439.  
  1440.  - Mapping Function:  isspace (S)
  1441.      Return 1 for whitespace characters (space, formfeed, newline,
  1442.      carriage return, tab, and vertical tab).
  1443.  
  1444.  - Mapping Function:  isupper (S)
  1445.      Return 1 for upper case letters.
  1446.  
  1447.  - Mapping Function:  isxdigit (S)
  1448.      Return 1 for characters that are hexadecimal digits.
  1449.  
  1450.