Documentation Center

  • Trial Software
  • Product Updates

Pass String Arguments

For arguments that require char *, you can pass a MATLAB® string (a character array). For example, see the stringToUpper function in the shrlibsample library.

 stringToUpper C Function

libfunctions shows that you can use a MATLAB cstring for this input. Type:

libfunctions shrlibsample -full

 stringToUpper Function Signature

Create a MATLAB character array, str, and pass it as the input argument:

str = 'This was a Mixed Case string';
calllib('shrlibsample','stringToUpper',str)
ans =
   THIS WAS A MIXED CASE STRING

Although the input argument that MATLAB passes to stringToUpper resembles a pointer to type char, it is not a true pointer data type because it does not contain the address of the MATLAB character array, str. When the function executes, it returns the correct result, but does not modify the value in str. If you examine str, you find it is unchanged. Type:

str
str = 
  This was a Mixed Case string
Was this topic helpful?