If you intend to use x as a variable from data.mat instead of a function, explicitly declare it.
Similarly, to use an identifier x as a variable obtained from a script, declare it before invoking the
script. This new behavior also applies if the variable is implicitly introduced by the functions sim,
eval, evalc, and assignin.
This table shows some examples of how you can update your code.
Before
After
function myfunc
load data.mat;
disp(x(:))
end
function myfunc
load data.mat x;
disp(x(:))
end
function myfunc2
myscript; % Contains variable x
disp(x(:))
end
function myfunc2
x = [];
myscript;
disp(x(:))
end
Variables cannot be implicitly shared between parent and nested
functions
Starting in R2019b, sharing an identifier as a variable between a nested function on page 20-28 and
its parent function is possible only if the identifier is explicitly declared as a variable in the parent
function.
For example, in the following code, identifier x in myfunc is different from variable x in the nested
function. If x is a function on the path, MATLAB treats x in myfunc as a function and the code runs.
Otherwise, MATLAB throws an error.
function myfunc
nested;
x(3) % x is not a shared variable
function nested
x = [1 2 3];
end
end
In previous releases, if x was a function on the path, MATLAB treated it as a function in myfunc and
as a variable in nested. If x was not a function on the path, MATLAB treated it as a variable shared
between myfunc and nested. This resulted in code whose output was dependent on the state of the
path.
To use an identifier as a variable shared between parent and nested functions, you might need to
update your code. For example, you can initialize the identifier to an empty array in the parent
function.
Update Code for R2019b Changes to Function Precedence Order
20-41
Similarly, to use an identifier x as a variable obtained from a script, declare it before invoking the
script. This new behavior also applies if the variable is implicitly introduced by the functions sim,
eval, evalc, and assignin.
This table shows some examples of how you can update your code.
Before
After
function myfunc
load data.mat;
disp(x(:))
end
function myfunc
load data.mat x;
disp(x(:))
end
function myfunc2
myscript; % Contains variable x
disp(x(:))
end
function myfunc2
x = [];
myscript;
disp(x(:))
end
Variables cannot be implicitly shared between parent and nested
functions
Starting in R2019b, sharing an identifier as a variable between a nested function on page 20-28 and
its parent function is possible only if the identifier is explicitly declared as a variable in the parent
function.
For example, in the following code, identifier x in myfunc is different from variable x in the nested
function. If x is a function on the path, MATLAB treats x in myfunc as a function and the code runs.
Otherwise, MATLAB throws an error.
function myfunc
nested;
x(3) % x is not a shared variable
function nested
x = [1 2 3];
end
end
In previous releases, if x was a function on the path, MATLAB treated it as a function in myfunc and
as a variable in nested. If x was not a function on the path, MATLAB treated it as a variable shared
between myfunc and nested. This resulted in code whose output was dependent on the state of the
path.
To use an identifier as a variable shared between parent and nested functions, you might need to
update your code. For example, you can initialize the identifier to an empty array in the parent
function.
Update Code for R2019b Changes to Function Precedence Order
20-41
