Pass MATLAB Character Vector to Python Method

This example shows how to display the contents of a folder using the Python® os.listdir method. The listdir method returns a list containing the names of the entries in the folder given by the path input argument.

Create a MATLAB® variable representing a valid folder.

folder = fullfile(matlabroot,'help','examples');

Pass folder to the os.listdir function. MATLAB automatically converts folder to the Python str type.

F = py.os.listdir(folder)
F = 

  Python list with no properties.

    ['graphics', 'graphics2', 'matlab']

MATLAB displays a list of folders, based on your product.

Related Topics

Was this topic helpful?