Starting in R2019b
Updated Code
R2019a and Earlier
This code throws an error when
starting MATLAB with the -
nojvm option.
function myfunc
import java.lang.String % Errors
if ~usejava('jvm')
% Statement never executes
disp('This function requires Java');
else
% Do something with Java String class
end
end
Remove call to usejava.
function myfunc
import java.lang.String % Errors
% Do something with java String class
end
This code displays a message
when starting MATLAB with the
-nojvm option.
function myfunc
import java.lang.String
if ~usejava('jvm')
% Display message
disp('This function requires Java')
else
% Do something with Java String cla
end
end
Nested functions inherit import statements from parent functions
Starting in R2019b, nested functions inherit import statements from the parent function. In R2019a
and earlier, nested functions did not inherit import statements from their parent functions.
Starting in R2019b
R2019a and Earlier
function myfunc
% Package p1 has functions plot and bar
import p1.plot
import p1.*
nest
function nest
plot
% Calls p1.plot
bar
% Calls p1.bar
end
end
function myfunc
% Package p1 has functions plot and bar
import p1.plot
import p1.*
nest
function nest
plot
% Calls plot function on path
bar
% Calls bar function on path
end
end
Change in precedence of compound name resolution
Starting in R2019b, MATLAB resolves compound names differently. A compound name is comprised
of several parts joined by a dot (for example, a.b.c), which can be used to reference package
members. With R2019b, MATLAB resolves compound names by giving precedence to the longest
matching prefix. In previous releases, the precedence order followed a more complex set of rules.
For example, suppose a package pkg contains a class foo with a static method bar and also a
subpackage foo with a function bar.
+pkg/@foo/bar.m % bar is a static method of class foo
+pkg/+foo/bar.m % bar is a function in subpackage foo
In R2019b, a call to which pkg.foo.bar returns the path to the package function.
which pkg.foo.bar
+pkg/+foo/bar.m
Previously, a static method took precedence over a package function in cases where a package and a
class had the same name.
20 Function Basics
20-44
Précédent

- 752/1450

Suivant