MATLAB Answers


Animating a circle based on diameter data

Asked by Kelly McGuire on 26 Apr 2018
Latest activity Edited by Ameer Hamza
on 27 Apr 2018
I have two columns of data. In one is the frame number (which I may convert to time in nanoseconds) and in the other is the diameter of an object at that frame or time. I would like to create an animated circle, where the circle is animated based on the changing diameter. For example, at frame 0 the diameter is 10 nanometers, at frame 1 the diameter is 9.5 nanometers, at frame 2 the diameter is 9 nanometers, and so on for about 4,000 frames. I would like to create a circle that is animated, changing by those diameters per frame. Can someone help with this? Thanks!


Sign in to comment.


1 Answer

Answer by Ameer Hamza
on 26 Apr 2018
Edited by Ameer Hamza
on 27 Apr 2018
 Accepted Answer

Here is a general sketch to create such animation. This code will write the animation frames to a video, you can modify the code according to your requirement.
animationWriter = VideoWriter('animation_file');
for i=1:4000
% create data for circle plot or any other processing you want to do
f = ....; % write your plotting command here using plot() or any other graphics primitive
frame = getframe(gcf);
writeVideo(animationWriter, frame);


This reference also provides an excellent demo.
Thanks for the help! Couple of questions. 1) Is 'animation_file' the name I want to give my file and without quotes? 2) How does the i=4000 know to use a column of data points? 3) Forgive my novice status, but how would the f = ... part know to use the data points in my column as the diameter of the circle? Thanks!
1) You will need to input file name in quotes e.g. 'myFile'.
2) I put ... in my code for you to fill. You can write your own code there. You can plot whatever you want there and it will create an animation based on plots you create.

Sign in to comment.