Open In App

Set environment variable in MATLAB

Setting environment variables with the help of setenv() function. The setenv() function is used to set the specified value of an operating system environment variable. Here the environment variable “name” will be replaced with “value”, where “name” and “value” is its parameters.

Syntax

setenv(name, value)

Parameters: This function accepts two parameters, which are illustrated below:



Return Value: It returns the replaced variable name.

Example 1  






% MATLAB code for environment variable
% GFG has been created and later replaced 
% with "C:\GFG" using the setenv() function
setenv('GFG','C:\GFG');
  
% Getting the current variable name
getenv('GFG')

 
 

Output:

 

 

Example 2

 




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

 
 

Output:

 

 

Article Tags :