MATLAB: Does GETENV or TEMPDIR give results with tilda(~) in MATLAB 7.1 (R14SP3)

~getenvMATLABpathtempdirtilda

I want to obtain he path of my environment variables in MATLAB using the GETENV function as follows:
getenv('TEMP')
The output is:
C:\DOCUMEN~1\FIRST~.LAS\LOCALS~1\Temp
The expected output is:
C:\Documents and Settings\first.last\Local Settings\Temp

Best Answer

This issue is due to DOS abbreviating the path names for the environment variables created in DOS. When these environment variables are accessed, DOS interprets tilda(~) as an abbreviation and expands it to the appropriate path name.
The function GETENV searches the underlying operating system's environment list for a string of the form name=value, where name is the input string. You can cross check the value of the environment variable returned by MATLAB with the value in Windows OS by going to
'Start->Settings->Control Panel->System->Advanced->Environment Variables'
from Windows Desktop.