This is a setting that that MATLAB finds from the system environment variables. You can set or query the environment variable using the SETENV and the GETENV functions from within MATLAB as well. Please see below for the system level settings.
MATLAB will check for the environment variable 'TMP' (getenv('TMP') )from the system and if this is empty MATLAB will use '/TMP/' as the temporary directory. You can set the 'TMP' environment variable to some other directory and MATLAB will use that as the TEMPDIR.
FOR WINDOWS: MATLAB similarly checks the 'TEMP' environment variables and if it is empty, MATLAB will use the present working directory(PWD).
In order to change the system setting, here is a quick example :