This MATLAB mex function fetches the name of the current user. The function is only for windows operating system. It was tested for MATLAB release 12.1 running under windows 12.1
COMPILE AND LINK AS A MATLAB MEX DLL:
on MATLAB command prompt to compile and link the program as a MATLAB mex dll.
The resulting file getusername.dll may be called just like a MATLAB m-file function with syntax:
[username] = getusername
without any input arguments.
I want to rate Martin Lechner's alternative as 5/5.
Under unix getenv('USER'); also works, string is casesensitive
Matlab 6.5 for windows operating system:
getenv('UserName') also works