unsetenv
Syntax
Description
Examples
Create and Test Environment Variable
Create environment variable myVar
, and then check that it exists.
setenv("myVar","myValue"); isenv("myVar")
ans = logical
1
Remove myVar
, and then check that it no longer exists.
unsetenv("myVar"); isenv("myVar")
ans = logical
0
Create and Test Multiple Environment Variables
Create multiple environment variables, and then check that they exist.
setenv(["Var1" "Var2" "Var3" "Var4"],["Val1" "Val2" "Val3" "Val4"]); isenv(["Var1" "Var2"; "Var3" "Var4"])
ans = 2x2 logical array
1 1
1 1
Remove two of the environment variables using unsetenv
, and then check that they no longer exist.
unsetenv(["Var1" "Var4"]); isenv(["Var1" "Var2"; "Var3" "Var4"])
ans = 2x2 logical array
0 1
1 0
You can also remove environment variables using setenv
with missing
. Change the value of one environment variable and remove another.
setenv(["Var2" "Var3"],["ValB" missing]); isenv(["Var1" "Var2"; "Var3" "Var4"])
ans = 2x2 logical array
0 1
0 0
Input Arguments
varname
— Environment variable names
string scalar | character vector | string array | cell array of character vectors
Environment variable names, specified as a string scalar, character vector, string array, or cell array of character vectors.
Example: "PATH"
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Code generation does not support the use of
unsetenv
insideparfor
loops.
Version History
Introduced in R2022bR2023a: Remove multiple environment variables
Remove multiple environment variables by using unsetenv
with a string
array or cell array of character vectors as input.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)