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:
expanduser('~/Downloads/foo')
OS | expanded |
---|---|
Linux | /home/user/Downloads/foo |
Windows | C:\users\user\Downloads\foo |
Mac | /Users/user/Downloads/foo |
Python
Python paths starting with ~ need pathlib.Path('~/mypath').expanduser()
function to expand this into the user directory.
import pathlib
pathlib.Path('~/Downloads/foo').expanduser()