How to create a gif?

4 ビュー (過去 30 日間)
Niloufar
Niloufar 2022 年 12 月 27 日
回答済み: Simon Chan 2022 年 12 月 27 日
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

採用された回答

Simon Chan
Simon Chan 2022 年 12 月 27 日
Check the answers from here

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by