| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
setenv(name, value)
setenv(name)
setenv(name, value) sets the value of an environment variable belonging to the underlying operating system. Inputs name and value are both strings. If name already exists as an environment variable, then setenv replaces its current value with the string given in value. If name does not exist, setenv creates a new environment variable called name and assigns value to it.
setenv(name) is equivalent to setenv(name, '') and assigns a null value to the variable name. On the Microsoft Windows platform, this is equivalent to undefining the variable. On most UNIX[1] platforms, it is possible to have an environment variable defined as empty.
The maximum number of characters in name is 215 - 2 (or 32766). If name contains the character =, setenv throws an error. The behavior of environment variables with = in the name is not well-defined.
On all platforms, setenv passes the name and value strings to the operating system unchanged. Special characters such as ;, /, :, $, %, etc. are left unexpanded and intact in the variable value.
Values assigned to variables using setenv are picked up by any process that is spawned using the MATLAB system, unix, dos or ! functions. You can retrieve any value set with setenv by using getenv(name).
% Set and retrieve a new value for the environment variable TEMP:
setenv('TEMP', 'C:\TEMP');
getenv('TEMP')% Append the Perl\bin directory to your system PATH variable:
setenv('PATH', [getenv('PATH') ';D:\Perl\bin']);[1] UNIX is a registered trademark of The Open Group in the United States and other countries.
![]() | setdisp (hgsetget) | setfield | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |