Animated imagesc movies in GNU Octave and Matlab

Related: Animated plots in Matplotlib


The pause() Matlab / Octave statement causes figures to refresh.

%% create data, 25 frames of 512x512 pixels
data = rand(512,512,25);

%% create blank image
h = imagesc(data(:,:,1));

%% for loop to play "movie"
for i = 1:size(data,3)
  set(h, 'cdata', data(:,:,i)) % update latest frame
  pause(0.01) % feel free to reduce, but keep greater than 0 to ensure redraw
end

Tags:

Categories:

Written by Michael Hirsch, Ph.D. //

Comments