| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
#include "matrix.h" int mxGetString(const mxArray *pm, char *str, mwSize strlen);
integer*4 mxGetString(pm, str, strlen) mwPointer pm character*(*) str mwSize strlen
Pointer to a string mxArray; that is, a pointer to an mxArray having the mxCHAR_CLASS class.
Starting location for the string. mxGetString writes the character data into str and then, in C, terminates the string with a NULL character (in the manner of C strings). str can point to either dynamic or static memory.
Maximum number of characters to read into str. Typically, in C, you set strlen to 1 plus the number of elements in the string mxArray to which pm points. See the mxGetM and mxGetN reference pages to find out how to get the number of elements.
0 on success, and 1 on failure. Possible reasons for failure include
mxArray is not a string array.
strlen is not large enough to store the entire mxArray. If so, the function returns 1 and truncates the string.
Call mxGetString to copy the character data of a string mxArray into a C-style string in C or a character array in Fortran. The copied string starts at str and contains no more than strlen-1 characters in C (no more than strlen characters in Fortran). In C, the C-style string is always terminated with a NULL character.
If the string array contains several rows, the function copies them into one long string array, one column at a time.
Use this function only with strings that represent single-byte character sets. For strings that represent multibyte character sets, use the C function mxArrayToString. Fortran users must allocate sufficient space for the return string to avoid possible truncation.
Examples:
explore.c in the matlabroot/extern/examples/mex folder
mxmalloc.c in the matlabroot/extern/examples/mx folder
mxArrayToString, mxCreateCharArray, mxCreateCharMatrixFromStrings, mxCreateString
![]() | mxGetScalar (C and Fortran) | mxIsCell (C and Fortran) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |