MATLAB Examples

Use Python str Type in MATLAB

This example shows how to use the Python® path separator character (;). In MATLAB®, a Python character is a py.str variable.

p = py.os.path.pathsep
p = 

  Python str with no properties.

    ;

MATLAB uses the same path separator character, ;.

c = pathsep
c =

  char

;

Compare the MATLAB variable type to the Python type. A py.str type is not equivalent to a MATLAB char type.

isequal(class(p),class(c))
ans =

  logical

   0

Convert p to a MATLAB type and append the character to a file name.

f = ['myfile' char(p)]
f =

  1×7 char array

myfile;