Anonymous functions can include resolved and unresolved identifiers
Starting in R2019b, anonymous functions can include both resolved and unresolved identifiers. In
previous releases, if any identifiers in an anonymous function were not resolved at creation time, all
identifiers in that anonymous function were unresolved.
Starting in R2019b
R2019a and Earlier
To evaluate the anonymous function, MATLAB
calls the local function lf with x defined in
myscript because lf in the anonymous function
resolves to the local function.
function myfun
myscript; % Includes x = 1 and lf = 10
f = @()lf(x);
f()
% Displays 'Inside lf'
end
% Local function to myfun
function lf(y)
disp('Inside lf');
end
MATLAB considers lf as an unresolved identifier
along with x, and used x to index into the
variable lf from myscript.
function myfun
myscript; % Includes x = 1 and lf = 10
f = @()lf(x);
f()
% Displays 10
end
% Local function to myfun
function lf(y)
disp('Inside lf');
end
See Also
import
More About
•
“Import Classes”
Update Code for R2019b Changes to Function Precedence Order
20-45
Starting in R2019b, anonymous functions can include both resolved and unresolved identifiers. In
previous releases, if any identifiers in an anonymous function were not resolved at creation time, all
identifiers in that anonymous function were unresolved.
Starting in R2019b
R2019a and Earlier
To evaluate the anonymous function, MATLAB
calls the local function lf with x defined in
myscript because lf in the anonymous function
resolves to the local function.
function myfun
myscript; % Includes x = 1 and lf = 10
f = @()lf(x);
f()
% Displays 'Inside lf'
end
% Local function to myfun
function lf(y)
disp('Inside lf');
end
MATLAB considers lf as an unresolved identifier
along with x, and used x to index into the
variable lf from myscript.
function myfun
myscript; % Includes x = 1 and lf = 10
f = @()lf(x);
f()
% Displays 10
end
% Local function to myfun
function lf(y)
disp('Inside lf');
end
See Also
import
More About
•
“Import Classes”
Update Code for R2019b Changes to Function Precedence Order
20-45
