I chose this animation example to highlight one of my favorite new features of R2021a, animation playback controls in live scripts. This release has many great new features, and you may actually miss this one if you don't closely read through the Release Notes.
Animations in live scripts had been possible for a few releases now. With R2021a, you can now play back the animation without re-running the code. You get a play control below the plot, with the ability to change the playback speed.
Notice that I'm also using the new Name=Value syntax for the optional arguments.
Run in your browser NOW
Did you know that there's also a new feature in the blogs to run the code right in your browser? Click on the "Run in your browser" button below, and you will see the live script for this blog post open up in an online version of MATLAB. Run the code and you should see the animation playback control after it finishes running.
Give it a try now and let us know what you think here.
Helper function for the animation
function dy = double_pendulum(t, y, m, L)
% System of ODEs for a double pendulum (mass m and link length L)
% See http://en.wikipedia.org/wiki/Double_pendulum for the differential