setenv
Sets an environment variable for the current process.
Category: Environment and Settings > System Commands
Syntax
setenv(name, value)
Sets variable name to value.
setenv(name)
Sets name to an empty value.
Description
The change lasts for the current session and is inherited by programs started with system; it does not alter the permanent environment of the operating system. Setting an existing variable replaces its value.
Input arguments
name- Variable name.
value- Text to store.
Example
Pass a value to a child process
setenv('GREETING', 'olá');
disp(getenv('GREETING'))
setenv('GREETING', 'hi');
disp(getenv('GREETING'))
[~, out] = system('echo %GREETING%');
disp(strtrim(out))
Output
olá
hi
hi
Notes
The last line of the example uses the Windows syntax %NAME%; on other systems a shell would use $NAME.