How to create a gif?

4 visualizzazioni (ultimi 30 giorni)
Niloufar
Niloufar il 27 Dic 2022
Risposto: Simon Chan il 27 Dic 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

Risposta accettata

Simon Chan
Simon Chan il 27 Dic 2022
Check the answers from here

Più risposte (0)

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by