Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Get environment variable in MATLAB

  • Last Updated : 06 Jul, 2021

In this article, we are going to discuss “Getting environment variable”, which can be done using getenv() function. The getenv() function is used to get the operating system environment variable.

Syntax:

value = getenv(name)

Parameters: This function accepts a parameter name parameter.

  • name: This is the specified name for which environmental variable is going to be searched.

Return Value: It returns the operating system environment variable.

Example 1

Matlab






% MATLAB code for Environment Variable GFG
% has been created and later replaced with "C:\GFG" variable
% Calling the setenv() function
% to replace the "GFG" name
% with value "C:\GFG"
setenv('GFG','C:\GFG');
 
% Calling the getenv() function to
% Get the current environment variable name
getenv('GFG')

 

 

Output

 

ans = C:\GFG

 

Here the getenv() function returns the current environmental variable name “C:\GFG”.

 

Example 2



 

Matlab




% MATLAB code for Calling the setenv()
% to set the value
% "D:\geeksforgeeks\gfg" over
% the variable "a"
setenv('a','D:\geeksforgeeks\gfg');
 
% Calling the getenv() function to
% Get the current environment variable name
getenv('a')

 

 

Output

 

ans = D:\geeksforgeeks\gfg

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :