Skip to content

Instantly share code, notes, and snippets.

@jamesmyatt
Last active June 16, 2016 18:06
Show Gist options
  • Save jamesmyatt/7c657a3b22f535eb41dc55e12e4440da to your computer and use it in GitHub Desktop.
Save jamesmyatt/7c657a3b22f535eb41dc55e12e4440da to your computer and use it in GitHub Desktop.
List of MATLAB environment variables
%% Create additional variables
setenv('ExampleVar1', 'on')
setenv('ExampleVar2', 'yes')
setenv('ExampleVar3', 'true')
%% List of Java environment variables
env_java = java.lang.System.getenv();
keys_java = cell(env_java.keySet.toArray());
%% List of system environment variables
if ispc, cmd = 'set'; else cmd = 'env'; end
[~, out] = system(cmd);
env_sys = regexp(strtrim(out), '^(.*)=(.*)$', 'tokens', ...
'lineanchors', 'dotexceptnewline');
env_sys = vertcat(env_sys{:});
keys_sys = env_sys(:, 1);
%% Keys defined in Java list only
keys_java_only = setdiff(keys_java, keys_sys)
% On my machine:
% =::
%% Keys defined in system list only
keys_sys_only = setdiff(keys_sys, keys_java)
% On my machine:
% ExampleVar1
% ExampleVar2
% ExampleVar3
% PROMPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment