In this post I discuss some of the new features in MATLAB R2022a, focusing on ones that relate to my particular interests. See the release notes for a detailed list of the many changes in MATLAB and its toolboxes. For my articles about new features in earlier releases, see here.
MATLAB Online now has themes, including a dark theme (which is my preference). We will have to wait for a future release for themes to be supported on desktop MATLAB.
I recall that @nhigham was asking for this. Currently @MATLAB Online only at the moment though. Desktop MATLAB isn’t there yet
— Mike Croucher (@walkingrandomly) March 11, 2022
One can now write
qr(A,'econ') instead of
gsvd(A,B,'econ') instead of
gsvd(A,B) for the “economy size” decompositions. This is useful as the
'econ' form is more descriptive. The
svd function already supported the
'econ' argument. The economy-size QR factorization is sometimes called the thin QR factorization.
Tie Breaking in the round Function
round function, which rounds to the nearest integer, now breaks ties by rounding away from zero by default and has several other tie-breaking options (albeit not stochastic rounding). See a sequence of four blog posts on this topic by Cleve Moler starting with this one from February 2021.
Tolerances for null and orth
null (nullspace) and
orth (orthonormal basis for the range) functions now accept a tolerance as a second argument, and any singular values less than that tolerance are treated as zero. The default tolerance is
max(size(A)) * eps(norm(A)). This change brings the two functions into line with
rank, which already accepted the tolerance. If you are working in double precision (the MATLAB default) and your matrix has inherent errors of order (for example), you might set the tolerance to , since singular values smaller than this are indistinguishable from zero.
Unit Testing Reports
The unit testing framework can now generate docx, html, and pdf reports after test execution, by using the function
generatePDFReport in the latter case. This is useful for keeping a record of test results and for printing them. We use unit testing in Anymatrix and have now added an option to return the results in a variable so that the user can call one of these new functions.
Checking Arrays for Special Values
Previously, if you wanted to check whether a matrix had all finite values you would need to use a construction such as
all(isfinite(A),'all'). The new
allfinite function does this in one go:
allfinite(A) returns true or false according as all the elements of
A are finite or not, and it works for arrays of any dimension.
anymissing check for NaNs or missing values. A missing value is a NaN for numerical arrays, but is indicated in other ways for other data types.
Linear Algebra on Multidimensional Arrays
pageinv functions solve linear equations and calculate matrix inverses using pages of -dimensional arrays, while
tensorprod calculates tensor products (inner products, outer products, or a combination of the two) between two -dimensional arrays.
The append option of the
exportgraphics function now supports the GIF format, enabling one to create animated GIFs (previously only multipage PDF files were supported). The key command is
exportgraphics(gca,file_name,"Append",true). There are other ways of creating animated GIFs in MATLAB, but this one is particularly easy. Here is an example M-file (based on cheb3plot in MATLAB Guide) with its output below.
%CHEB_GIF Animated GIF of Chebyshev polynomials. % Based on cheb3plot in MATLAB Guide. x = linspace(-1,1,1500)'; p = 49 Y = ones(length(x),p); Y(:,2) = x; for k = 3:p Y(:,k) = 2*x.*Y(:,k-1) - Y(:,k-2); end delete cheby_animated.gif a = get(groot,'defaultAxesColorOrder'); m = length(a); for j = 1:p-1 % length(k) plot(x,Y(:,j),'LineWidth',1.5,'color',a(1+mod(j-1,m),:)); xlim([-1 1]), ylim([-1 1]) % Must freeze axes. title(sprintf('%2.0f', j),'FontWeight','normal') exportgraphics(gca,"cheby_animated.gif","Append",true) end