Animated Gif mit Matlab erstellen: Unterschied zwischen den Versionen

Aus HSHL Mechatronik
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 19: Zeile 19:
       end
       end
end
end
</source>
 




== Ergebnis ==
== Ergebnis ==
[[Datei:AnimatedGif.gif]]
[[Datei:AnimatedGif.gif]]
== Beispiel 2 ==
<source lang="matlab" style="font-size:medium">
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)
</source>
[[Datei:AnimatedGif2.m]]
Quelle: [http://www.mathworks.com/matlabcentral/fileexchange/21944-animated-gif/content/Animated_GIF/html/AnimatedGif.html]
----
----
→ zurück zum Hauptartikel: [[Einführung_in_MATLAB|Einführung in MATLAB]]
→ zurück zum Hauptartikel: [[Einführung_in_MATLAB|Einführung in MATLAB]]

Version vom 30. Mai 2014, 09:45 Uhr

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 ==
[[Datei:AnimatedGif.gif]]

== Beispiel 2 ==
<source lang="matlab" style="font-size:medium">
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