Skip to content

Instantly share code, notes, and snippets.

@drhirsch
Last active September 2, 2016 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhirsch/ed1482a4b16a98efeda87c60b3017594 to your computer and use it in GitHub Desktop.
Save drhirsch/ed1482a4b16a98efeda87c60b3017594 to your computer and use it in GitHub Desktop.
example animated movie in Matlab or Octave
%% create data, 25 frames of 512x512 pixels
data = rand(512,512,25);
%% create blank image
img = imagesc(rand(512));
ht = title(''); % to show frame number
%% for loop to play "movie"
for i = 1:25
set(img,'cdata',data(:,:,i)) % update latest frame
set(ht,'string',['Frame (',num2str(i),'/25)'])
pause(0.2) % feel free to reduce, but keep greater than 0 to ensure redraw
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment