Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 3e60ff9d4d6f58c8fbd17208f14089fa > files > 93

octave-doc-3.2.3-3mdv2010.0.i586.rpm

<html lang="en">
<head>
<title>Character Strings in Mex-Files - 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="Mex_002dFiles.html#Mex_002dFiles" title="Mex-Files">
<link rel="prev" href="Working-with-Matrices-and-Arrays-in-Mex_002dFiles.html#Working-with-Matrices-and-Arrays-in-Mex_002dFiles" title="Working with Matrices and Arrays in Mex-Files">
<link rel="next" href="Cell-Arrays-with-Mex_002dFiles.html#Cell-Arrays-with-Mex_002dFiles" title="Cell Arrays with Mex-Files">
<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="Character-Strings-in-Mex-Files"></a>
<a name="Character-Strings-in-Mex_002dFiles"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Cell-Arrays-with-Mex_002dFiles.html#Cell-Arrays-with-Mex_002dFiles">Cell Arrays with Mex-Files</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Working-with-Matrices-and-Arrays-in-Mex_002dFiles.html#Working-with-Matrices-and-Arrays-in-Mex_002dFiles">Working with Matrices and Arrays in Mex-Files</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Mex_002dFiles.html#Mex_002dFiles">Mex-Files</a>
<hr>
</div>

<h4 class="subsection">A.2.3 Character Strings in Mex-Files</h4>

<p>As mex-files do not make the distinction between single and double
quoted strings within Octave, there is perhaps less complexity in the
use of strings and character matrices in mex-files.  An example of their
use, that parallels the demo in <samp><span class="file">stringdemo.cc</span></samp>, is given in the
file <samp><span class="file">mystring.c</span></samp>, as seen below.

<pre class="example"><pre class="verbatim">     #include &lt;string.h>
     #include "mex.h"
     
     void
     mexFunction (int nlhs, mxArray *plhs[], int nrhs, 
     	     const mxArray *prhs[])
     {
       mwIndex i, j;
       mwSize m, n;
       mxChar *pi, *po;
     
       if (nrhs != 1 || ! mxIsChar (prhs[0]) || 
           mxGetNumberOfDimensions (prhs[0]) > 2)
         mexErrMsgTxt ("expecting char matrix");
     
       m = mxGetM (prhs[0]);
       n = mxGetN (prhs[0]);
       pi = mxGetChars (prhs[0]);
       plhs[0] = mxCreateNumericMatrix (m, n, mxCHAR_CLASS, 
     				   mxREAL);
       po = mxGetChars (plhs[0]);
     
       for (j = 0; j &lt; n; j++)
         for (i = 0; i &lt; m; i++)
           po [j*m + m - 1 - i] = pi [j*m + i];
     }
</pre></pre>
   <p class="noindent">An example of its expected output is

<pre class="example">     mystring(["First String"; "Second String"])
     &rArr; s1 = Second String
             First String
</pre>
   <p>Other functions in the mex interface for handling character strings are
<code>mxCreateString</code>, <code>mxArrayToString</code>, and
<code>mxCreateCharMatrixFromStrings</code>.  In a mex-file, a character string
is considered to be a vector rather than a matrix.  This is perhaps an
arbitrary distinction as the data in the mxArray for the matrix is
consecutive in any case.

   </body></html>