Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 149

octave-doc-3.6.4-3.mga4.noarch.rpm

<html lang="en">
<head>
<title>Cell Arrays of Strings - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<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>
   <!-- cellstr src/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-470"></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.

<!-- iscellstr src/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-471"></a></var><br>
<blockquote><p>Return true if every element of the cell array <var>cell</var> is a
character string. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dischar.html#doc_002dischar">ischar</a>. 
</p></blockquote></div>

   </body></html>