Matlab tilde expanduser

Matlab does not consistently understand “~” to be the user home directory, especially on Windows. Use our expanduser() function that works with Matlab and GNU Octave. It converts ~ into your home directory on Linux, macOS and Windows:

OS expanded
Linux /home/user/Downloads/foo
Windows C:\users\user\Downloads\foo
macOS /Users/user/Downloads/foo


Python paths starting with ~ need pathlib.Path('~/mypath').expanduser() function to expand this into the user directory.

import pathlib