Animated Gif mit Matlab erstellen

Aus HSHL Mechatronik
Zur Navigation springen Zur Suche springen
x = 0:0.01:1;
% Grafik erstellen
figure(1)
% Dateiname festlegen
filename = 'AnimatedGif.gif';
% 2 fps
for n = 1:0.5:5
      y = x.^n;
      plot(x,y)
      drawnow
      frame = getframe(1);
      im = frame2im(frame);
      [imind,cm] = rgb2ind(im,256);
      if n == 1;
          imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
      else
          imwrite(imind,cm,filename,'gif','WriteMode','append');
      end
end


Ergebnis

Beispiel 2

Z = peaks;
surf(Z)
axis tight
set(gca,'nextplot','replacechildren','visible','off')
f = getframe;
[im,map] = rgb2ind(f.cdata,256,'nodither');
im(1,1,1,20) = 0;
for k = 1:20
  surf(cos(2*pi*k/20)*Z,Z)
  f = getframe;
  im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
end
imwrite(im,map,'DancingPeaks.gif','DelayTime',0,'LoopCount',inf)

Datei:AnimatedGif2.m

Quelle: [1]


→ zurück zum Hauptartikel: Einführung in MATLAB