Sophie

Sophie

distrib > Mandriva > current > x86_64 > by-pkgid > a3a677d80d3c0f62bd8cfbb738fb1e85 > files > 88

octave-doc-3.2.4-1mdv2010.1.x86_64.rpm

<html lang="en">
<head>
<title>Cell Arrays of Strings - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Cell-Arrays.html#Cell-Arrays" title="Cell Arrays">
<link rel="prev" href="Indexing-Cell-Arrays.html#Indexing-Cell-Arrays" title="Indexing Cell Arrays">
<link rel="next" href="Processing-Data-in-Cell-Arrays.html#Processing-Data-in-Cell-Arrays" title="Processing Data in Cell Arrays">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Cell-Arrays-of-Strings"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Processing-Data-in-Cell-Arrays.html#Processing-Data-in-Cell-Arrays">Processing Data in Cell Arrays</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Indexing-Cell-Arrays.html#Indexing-Cell-Arrays">Indexing Cell Arrays</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Cell-Arrays.html#Cell-Arrays">Cell Arrays</a>
<hr>
</div>

<h4 class="subsection">6.2.4 Cell Arrays of Strings</h4>

<p>One common use of cell arrays is to store multiple strings in the same
variable.  It is also possible to store multiple strings in a
character matrix by letting each row be a string.  This, however,
introduces the problem that all strings must be of equal length. 
Therefore, it is recommended to use cell arrays to store multiple
strings.  For cases, where the character matrix representation is required
for an operation, there are several functions that convert a cell
array of strings to a character array and back.  <code>char</code> and
<code>strvcat</code> convert cell arrays to a character array
(see <a href="Concatenating-Strings.html#Concatenating-Strings">Concatenating Strings</a>), while the function <code>cellstr</code>
converts a character array to a cell array of strings:

<pre class="example">     a = ["hello"; "world"];
     c = cellstr (a)
          &rArr; c =
              {
                [1,1] = hello
                [2,1] = world
              }
</pre>
   <!-- ov-cell.cc -->
   <p><a name="doc_002dcellstr"></a>

<div class="defun">
&mdash; Built-in Function:  <b>cellstr</b> (<var>string</var>)<var><a name="index-cellstr-397"></a></var><br>
<blockquote><p>Create a new cell array object from the elements of the string
array <var>string</var>. 
</p></blockquote></div>

   <p>One further advantage of using cell arrays to store multiple strings is
that most functions for string manipulations included with Octave
support this representation.  As an example, it is possible to compare
one string with many others using the <code>strcmp</code> function.  If one of
the arguments to this function is a string and the other is a cell array
of strings, each element of the cell array will be compared to the string
argument:

<pre class="example">     c = {"hello", "world"};
     strcmp ("hello", c)
          &rArr; ans =
             1   0
</pre>
   <p class="noindent">The following string functions support cell arrays of strings:
<code>char</code>, <code>strvcat</code>, <code>strcat</code> (see <a href="Concatenating-Strings.html#Concatenating-Strings">Concatenating Strings</a>), <code>strcmp</code>, <code>strncmp</code>, <code>strcmpi</code>,
<code>strncmpi</code> (see <a href="Comparing-Strings.html#Comparing-Strings">Comparing Strings</a>), <code>str2double</code>,
<code>deblank</code>, <code>strtrim</code>, <code>strtrunc</code>, <code>strfind</code>,
<code>strmatch</code>, , <code>regexp</code>, <code>regexpi</code> (see <a href="Manipulating-Strings.html#Manipulating-Strings">Manipulating Strings</a>) and <code>str2double</code> (see <a href="String-Conversions.html#String-Conversions">String Conversions</a>).

   <p>The function <code>iscellstr</code> can be used to test if an object is a
cell array of strings.

<!-- ov-cell.cc -->
   <p><a name="doc_002discellstr"></a>

<div class="defun">
&mdash; Built-in Function:  <b>iscellstr</b> (<var>cell</var>)<var><a name="index-iscellstr-398"></a></var><br>
<blockquote><p>Return true if every element of the cell array <var>cell</var> is a
character string
</p></blockquote></div>

<!-- ./general/cellidx.m -->
   <p><a name="doc_002dcellidx"></a>

<div class="defun">
&mdash; Function File: [<var>idxvec</var>, <var>errmsg</var>] = <b>cellidx</b> (<var>listvar, strlist</var>)<var><a name="index-cellidx-399"></a></var><br>
<blockquote><p>Return indices of string entries in <var>listvar</var> that match strings
in <var>strlist</var>.

        <p>Both <var>listvar</var> and <var>strlist</var> may be passed as strings or
string matrices.  If they are passed as string matrices, each entry
is processed by <code>deblank</code> prior to searching for the entries.

        <p>The first output is the vector of indices in <var>listvar</var>.

        <p>If <var>strlist</var> contains a string not in <var>listvar</var>, then
an error message is returned in <var>errmsg</var>.  If only one output
argument is requested, then <var>cellidx</var> prints <var>errmsg</var> to the
screen and exits with an error. 
</p></blockquote></div>

   </body></html>