MATLAB: Can’t I use the command publish or open up Simulink in MATLAB R2014a

MATLAB

I cannot use the "publish" command. It results in the following error: 
 
————————————————————————————————————–  ERROR: Error using cd Cannot CD to C:\Users\USER~1\AppData\Local\Temp (Name is nonexistent or not a directory).
Error in tempdir (line 30)
curr_dir = cd(tmp_dir);
Error in tempname (line 17)
dirname = tempdir;
Error in evalmxdom>instrumentAndRun (line 75)
[~,tempVar] = fileparts(tempname);
Error in evalmxdom (line 21)
[data,text,laste] = instrumentAndRun(file,cellBoundaries,imageDir,imagePrefix,options);
Error in publish (line 164)
dom = evalmxdom(file,dom,cellBoundaries,prefix,imageDir,outputDir,options);
Error in mdbpublish (line 55)
outputPath = publish(file, options);
Error using open (line 68)
NAME must contain a single string.
———————————————————————————————————————— 
 
I also cannot open Simulink either by typing "simulink" in the Command Window or by clicking on the Simulink Library icon. The following error results: 
 
————————————————————————————————————————-  ERROR: ans = Error using cd Cannot CD to C:\Users\USER~1\AppData\Local\Temp (Name is nonexistent or not a directory).
Error: The Simulink Library Browser failed to initialize.
Cannot CD to C:\Users\USER~1\AppData\Local\Temp (Name is nonexistent or not a directory).
————————————————————————————————————————– 
 
I have used the "publish" command in previous versions of MATLAB successfully. This error occurred after updating to R2014a.

Best Answer

The occurrence of this behavior is due to MATLAB not running with Administrator permission. To be more specific, the user has no access to folder:
 
C:\Users\USER~1\AppData\Local\Temp
 
This can be verified by changing directory into the above folder via the "cd" command in Windows Command Prompt. If access is limited, Windows Command Prompt will issue a warning that permission is denied to access the above folder.
 
To work around this issue, simply start MATLAB with Administrator permission. This can be achieved by right clicking on the icon MATLAB R2014a and select 'Run as Administrator'. To eliminate the need to run MATLAB as Administrator every time, one can turn off User Account Control by following the link below: