Error creating an animated GIF in Matlab
Mostrar comentarios más antiguos
Hello everyone,
I am trying to create a GIF showing the evolution of a height field (variable noted "h_reel") through time.
Unfortunately, I am encoutering an error and I am unable to performe what I am attempting to do... Here is my script :
p = figure(21);
filename = 'test.gif';
for i = index_intersection:nfichier
imagesc(h_reel(:,:,i));
[X, Y] = meshgrid([1:2048]*echelle,[1:2048]*echelle);
surf(X,Y,h_reel(:,:,i));
caxis([min(h_reel,[],'all') max(h_reel,[],'all')])
title(num2str(i))
shading interp;
%pause 0.25;
frame = getframe(p);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if i == 1
imwrite(imind,cm,filename,'gif','LoopCount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
Obtaining this error :
Error using matlab.internal.imagesci.wgifc
Can only append to GIF89a format GIFs.
Error in writegif (line 306)
matlab.internal.imagesci.wgifc(mat, map, filename,writemode,disposalmethod,delaytime,...
Error in imwrite (line 566)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Could someone help me to solve this problem please ?
Thank you in advance.
Sincerely,
Respuesta aceptada
Más respuestas (2)
yanqi liu
el 16 de Feb. de 2022
yes,sir,may be add some check flag,such as
p = figure(21);
filename = 'test.gif';
check_flag = 0;
for i = index_intersection:nfichier
imagesc(h_reel(:,:,i));
[X, Y] = meshgrid([1:2048]*echelle,[1:2048]*echelle);
surf(X,Y,h_reel(:,:,i));
caxis([min(h_reel,[],'all') max(h_reel,[],'all')])
title(num2str(i))
shading interp;
%pause 0.25;
frame = getframe(p);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% use check
if check_flag == 0
imwrite(imind,cm,filename,'gif','LoopCount',inf,'DelayTime',0.2);
check_flag = 1;
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.2);
end
end
Wissem
el 16 de Feb. de 2022
0 votos
Categorías
Más información sobre Images en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!