How to create a gif?

4 views (last 30 days)
Niloufar
Niloufar on 27 Dec 2022
Answered: Simon Chan on 27 Dec 2022
I have a code to generate a wave equation gif.but it just includes the last frame and I don't know what the problem is.here is my code:
clear;clc;close all;
%figure('Name','wave equation');
a = 1;
t0 = 1;
syms x;
f = @(x) ((a/t0)*x + a).*(x>-t0 & x<0) + ((-a/t0)*x + a).*(x>=0 & x<t0);
for c = 0:0.05:2
my_plot = fplot((f(x-c) + f(x+c))/2,[-t0 t0]);
frame = getframe(1);
im = frame2im(frame); %pause(0.01);
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,"C:\Users\ernika\wave_equation.gif",'gif'); %saved as mygif1
drawnow;
if(c~=2)
delete(my_plot)
end
end

Accepted Answer

Simon Chan
Simon Chan on 27 Dec 2022
Check the answers from here

More Answers (0)

Categories

Find more on Symbolic Math Toolbox 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!