Before
After
function myfunc
nested;
x(3)
function nested
x = [1 2 3];
end
end
function myfunc
x = [];
nested;
x(3)
function nested
x = [1 2 3];
end
end
Change in precedence of wildcard-based imports
Starting in R2019b, imported functions from wildcard-based imports have lower precedence than
variables, nested functions, and local functions. In R2019a and earlier, imports in a function
shadowed local functions and nested functions.
For example, in this code, the statement local() calls myfunc/local instead of pkg1.local in the
wildcard-based import. The statement nest() calls myfunc/nest instead of pkg1.nest.
Starting in R2019b
R2019a and Earlier
function myfunc
% Import includes functions local and nest
import pkg1.*
local()
% Calls myfunc/local
function nest
end
nest();
% Calls myfunc/nest
end
function local
end
function myfunc
% Import includes functions local and nest
import pkg1.*
local()
% Calls pkg1.local and
% displays warning since R2018a
function nest
end
nest();
% Calls pkg1.nest
end
function local
end
In the search results for import, look for statements that include the wildcard character (*).
Fully qualified import functions cannot have the same name as nested
functions
Starting in R2019b, fully qualified imports that share a name with a nested function in the same
scope throw an error.
Starting in R2019b
Updated Code
R2019a and Earlier
This function errors because it
shares a name with a nested
function in the same scope.
function myfunc
import pkg.nest % Errors
nest();
function nest
end
end
To call function nest from the
import statement, rename local
function myfunc/nest.
function myfunc
import pkg.nest
nest();
function newNest
end
end
This function calls function
nest from the import
statement.
function myfunc
import pkg.nest
nest(); % Calls pkg.nest
function nest
end
end
20 Function Basics
20-42
Précédent

- 750/1450

Suivant