/usr/share/doc/octave/octave.html/Character-Arrays.html is in octave-doc 4.2.2-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Character Arrays (GNU Octave)</title>
<meta name="description" content="Character Arrays (GNU Octave)">
<meta name="keywords" content="Character Arrays (GNU Octave)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Strings.html#Strings" rel="up" title="Strings">
<link href="Creating-Strings.html#Creating-Strings" rel="next" title="Creating Strings">
<link href="Escape-Sequences-in-String-Constants.html#Escape-Sequences-in-String-Constants" rel="prev" title="Escape Sequences in String Constants">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<a name="Character-Arrays"></a>
<div class="header">
<p>
Next: <a href="Creating-Strings.html#Creating-Strings" accesskey="n" rel="next">Creating Strings</a>, Previous: <a href="Escape-Sequences-in-String-Constants.html#Escape-Sequences-in-String-Constants" accesskey="p" rel="prev">Escape Sequences in String Constants</a>, Up: <a href="Strings.html#Strings" accesskey="u" rel="up">Strings</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Character-Arrays-1"></a>
<h3 class="section">5.2 Character Arrays</h3>
<p>The string representation used by Octave is an array of characters, so
internally the string <code>"dddddddddd"</code> is actually a row vector
of length 10 containing the value 100 in all places (100 is the ASCII code of
<code>"d"</code>). This lends itself to the obvious generalization to character
matrices. Using a matrix of characters, it is possible to represent a
collection of same-length strings in one variable. The convention used in
Octave is that each row in a character matrix is a separate string, but letting
each column represent a string is equally possible.
</p>
<p>The easiest way to create a character matrix is to put several strings
together into a matrix.
</p>
<div class="example">
<pre class="example">collection = [ "String #1"; "String #2" ];
</pre></div>
<p>This creates a 2-by-9 character matrix.
</p>
<p>The function <code>ischar</code> can be used to test if an object is a character
matrix.
</p>
<a name="XREFischar"></a><dl>
<dt><a name="index-ischar"></a>: <em></em> <strong>ischar</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Return true if <var>x</var> is a character array.
</p>
<p><strong>See also:</strong> <a href="Predicates-for-Numeric-Objects.html#XREFisfloat">isfloat</a>, <a href="Integer-Data-Types.html#XREFisinteger">isinteger</a>, <a href="Predicates-for-Numeric-Objects.html#XREFislogical">islogical</a>, <a href="Predicates-for-Numeric-Objects.html#XREFisnumeric">isnumeric</a>, <a href="Cell-Arrays-of-Strings.html#XREFiscellstr">iscellstr</a>, <a href="Built_002din-Data-Types.html#XREFisa">isa</a>.
</p></dd></dl>
<p>To test if an object is a string (i.e., a character vector and not a character
matrix) you can use the <code>ischar</code> function in combination with the
<code>isvector</code> function as in the following example:
</p>
<div class="example">
<pre class="example">ischar (collection)
⇒ 1
ischar (collection) && isvector (collection)
⇒ 0
ischar ("my string") && isvector ("my string")
⇒ 1
</pre></div>
<p>One relevant question is, what happens when a character matrix is
created from strings of different length. The answer is that Octave
puts blank characters at the end of strings shorter than the longest
string. It is possible to use a different character than the
blank character using the <code>string_fill_char</code> function.
</p>
<a name="XREFstring_005ffill_005fchar"></a><dl>
<dt><a name="index-string_005ffill_005fchar"></a>: <em><var>val</var> =</em> <strong>string_fill_char</strong> <em>()</em></dt>
<dt><a name="index-string_005ffill_005fchar-1"></a>: <em><var>old_val</var> =</em> <strong>string_fill_char</strong> <em>(<var>new_val</var>)</em></dt>
<dt><a name="index-string_005ffill_005fchar-2"></a>: <em></em> <strong>string_fill_char</strong> <em>(<var>new_val</var>, "local")</em></dt>
<dd><p>Query or set the internal variable used to pad all rows of a character
matrix to the same length.
</p>
<p>The value must be a single character and the default is <code>" "</code> (a
single space). For example:
</p>
<div class="example">
<pre class="example">string_fill_char ("X");
[ "these"; "are"; "strings" ]
⇒ "theseXX"
"areXXXX"
"strings"
</pre></div>
<p>When called from inside a function with the <code>"local"</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p></dd></dl>
<p>This shows a problem with character matrices. It simply isn’t possible to
represent strings of different lengths. The solution is to use a cell array of
strings, which is described in <a href="Cell-Arrays-of-Strings.html#Cell-Arrays-of-Strings">Cell Arrays of Strings</a>.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Creating-Strings.html#Creating-Strings" accesskey="n" rel="next">Creating Strings</a>, Previous: <a href="Escape-Sequences-in-String-Constants.html#Escape-Sequences-in-String-Constants" accesskey="p" rel="prev">Escape Sequences in String Constants</a>, Up: <a href="Strings.html#Strings" accesskey="u" rel="up">Strings</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|