MATLAB animatedPlotsTutorialArmin PDF
MATLAB animatedPlotsTutorialArmin PDF
https://courses.washington.edu/danielab/labwiki/index.php?title=Making_animations_in_MATLAB
You can create animated sequences with MATLAB graphics in three different
ways:
■ Save a number of different pictures and play them back as a movie.
■ Continually erase and redraw the objects on the screen, making
incremental changes with each redraw.
■ Redefine the XData, YData, ZData, and/or CData plot object properties,
optionally linking them to data sources (workspace variables) and updating
the properties via calls to refreshdata.
I’ll show you the recipe that works for me, but
there are many ways to achieve animated bliss
Topic covered:
Topic covered:
subplot(1,3,3)
plot(xpos,ypos,'k'); axis equal; axis off;
title('The path our circle will move along');
axlim = 15;
figure;
for c = 1:length(t)
helper ph=plotfilledcircle(circlesize(c), [xpos(c) ypos(c)]);
function
% we need to set the axes to an appropriate limit, otherwise they'll
% resize to always show the full circle:
axis([-axlim axlim -axlim axlim]);
axis square;
% create a counter that updates each iteration:
titlestr = sprintf('Frame: %03d', c);
title(titlestr);
if nargin < 2
circlecenter = [0 0];
end
if nargin < 3
fcol = [0 0 0];
end
end
Topic covered:
axlim = 15;
figure;
for c = 1:length(t)
fprintf('Frame: %03d\n', c); % display counter
Topic covered:
display frame
fill plot of circle from TIFF
stack
width
x
I like to set up fig_pos = [100 10 1024 768]; % position and size of the figure window
position variables fillplot_ax_pos = [80 320 400 400]; % position and size of fill plot
before entering the image_ax_pos = [580 320 400 400]; % image plot
sizedata_ax_pos = [50 170 1024-60 70]; % circle size graph
loop. posdata_ax_pos = [50 50 1024-60 100]; % circle position graph
Topic covered:
Declare where all fh= figure('color', fig_col, 'name', 'Tutorial animation movie', ...
'Position', fig_pos);
the elements
(axes) should be for k = startframe:endframe
for k = startframe:endframe
if movieflag == 1
frame = getframe(gcf); % capture current figure
aviobj = addframe(aviobj,frame); % append frame
end
if k < endframe
clf; % clear figure except for very last frame
end
end
if movieflag == 1
aviobj = close(aviobj);
end
Topic covered:
handle_ax = axes;
set(handle_ax, 'Units', 'pixels', 'Position', handle_ax_pos);
p1h(1)=plot(xpos,ypos, '-.');
set(p1h(1), 'Color', light_grey, 'LineWidth', 2);
hold on;
p1h(2) = plot(.....
set(p1h(2), 'Color', light_red, 'LineWidth', 1);
hold off;
Topic covered:
imread(ind) loads images from a file. Certain files (GIF, TIFF) can contain
multiple images in a stack. The ind tells the function which image it should
pull from the stack.
image_ax = axes;
set(image_ax, 'Units', 'pixels', 'Position', image_ax_pos);
try
img = imread('tiffstack.tiff', k); % load image of current index
catch ME1
% Get last segment of the error message identifier.
idSegLast = regexp(ME1.identifier, '(?<=:)\w+$', 'match');
disp(idSegLast);
error('Failed loading tiff image');
end
img = xor(1,img); % invert image to make it more exciting... XOR rules!
imagesc(img); colormap gray; axis off; axis image;
Topic covered:
Topic covered:
if movieflag == 1
fprintf('Saving movie...\n\n');
aviobj = close(aviobj);
end