getusername.m

来自「This contribution provides functions for」· M 代码 · 共 31 行

M
31
字号
function userName = getusername
%GETUSERNAME  Get user name.
%		USERNAME = GETUSERNAME returns the login name of the current MATLAB
%		user. Function should work for both Linux and Windows.
%
%		Markus Buehren
%		Last modified: 20.04.2008
%
%		See also GETHOSTNAME.

persistent userNamePersistent

if isempty(userNamePersistent)
  if ispc
    userName = getenv('username');
  else
    systemCall = 'whoami';
    [status, userName] = system(systemCall); %#ok
    if status ~= 0
      error('System call ''%s'' failed with return code %d.', systemCall, status);
    end
    userName = userName(1:end-1);
  end

  % save string for next function call
  userNamePersistent = userName;
else
  % return string computed before
  userName = userNamePersistent;
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?