Save animation as gif in GUI

7 views (last 30 days)
HSukas
HSukas on 31 Oct 2019
Hello everyone!
I am trying to save an animation as .gif.
My plot is similar with given code below, I created with animated line too.
The problem is that, when I defined my figure as f=figure of figure(1) it creates .gif file properly.
However, instead of plotting my figure in separate screen using "figure" command, I have to plot in an axes on matlab gui axes as given figure.
I tried it with : " f=(handles.axes_threeDOF); ". But when I use this function,gif file creates different part of the screen. I attached that file too.
Could you help me to solve my problem?
Thanks in advance.
I want to create a gif of this animation:
Ek Açıklama 2019-10-31 182135.png
But it creates as given below with this function " f=(handles.axes_threeDOF)"
test.gif
numpoints = 500;
x = linspace(0,4*pi,numpoints);
y = square(x);
y2 = 3 +square(x+1);
f = figure
h = animatedline('Color','b','LineWidth',2);
h2 = animatedline('Color','r','LineWidth',2);
grid on;
axis([0,12,-3,+6])
for k = 1:numpoints
addpoints(h,x(k),y(k))
addpoints(h2,x(k),y2(k))
drawnow
% Capture the plot as an image
frame = getframe(f);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% Write to the GIF File
if k == 1
imwrite(imind,cm,'test.gif','gif', 'Loopcount',inf);
else
imwrite(imind,cm,'test.gif','gif','WriteMode','append');
end
end

Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!