From: Judy on
Hi all,

Is anyone here familiar with making gifs from simple plots?

I only see examples online of varying peaks and nulls on a plane. http://www.mathworks.com/matlabcentral/fileexchange/21944-animated-gif

However, I don't want a 3D plot.. I just want a simple 2D.

Here's an example of what I've come up with so far, but I don't understand the im and maps that are being passed around.

t=-pi:0.01:pi,
figure,
f = getframe;
[im,map] = rgb2ind(f.cdata,256,'nodither');

for k=1:10,
plot(sin(k*t));
f=getframe;
im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
end

imwrite(im,map,'Test.gif','DelayTime',0,'LoopCount',inf);


This errors in :
??? Error using ==> capturescreen
The rectangle passed to getframe must be at least partially on screen.

Error in ==> getframe at 35
x=capturescreen(varargin{:});

Error in ==> MakeAnimatedGifsTest at 5
f = getframe;

Any help is much appreciated. Thank you :)
From: Kirill on
On Feb 19, 1:47 pm, "Judy " <sauwen...(a)gmail.com> wrote:
> Hi all,
>
> Is anyone here familiar with making gifs from simple plots?
>
> I only see examples online of varying peaks and nulls on a plane.  http://www.mathworks.com/matlabcentral/fileexchange/21944-animated-gif
>
> However, I don't want a 3D plot.. I just want a simple 2D.
>
> Here's an example of what I've come up with so far, but I don't understand the im and maps that are being passed around.
>
> t=-pi:0.01:pi,
> figure,
> f = getframe;
> [im,map] = rgb2ind(f.cdata,256,'nodither');
>
> for k=1:10,
> plot(sin(k*t));
> f=getframe;
> im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
> end
>
> imwrite(im,map,'Test.gif','DelayTime',0,'LoopCount',inf);
>
> This errors in :
> ??? Error using ==> capturescreen
> The rectangle passed to getframe must be at least partially on screen.
>
> Error in ==> getframe at 35
>   x=capturescreen(varargin{:});
>
> Error in ==> MakeAnimatedGifsTest at 5
> f = getframe;
>
> Any help is much appreciated.  Thank you :)

I remember shared a javascript with Matlab community that loads PNG
and displays them as a slide show. It was called htmlslideshowselect
or something like that. Not an animated GIF but close to it.

Kirill
From: Judy on
Thanks for the idea, but I really want to get this animated gif to work. I've now moved from doing 2D plots to displaying 3D data using imagesc.

Here is what I have so far:

clc;clear all;close all;
z=randn(50,50);
f = getframe;
[im,map] = rgb2ind(f.cdata,512,'nodither');

for k = 1:20
k

imagesc(k*randn(50,50))
f = getframe;
im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
end
imwrite(im,map,'Test.gif','DelayTime',1)

I actually get an animated gif, but the data and the coloring is not at all what I expect. Any ideas, or clues?

Thanks!!
From: Judy on
I figured out that z needs to be an image before you get its colormap. Here is the updated code... :)

clc;clear all;close all;
z=imagesc(randn(50,50));
f = getframe;
[im,map] = rgb2ind(f.cdata,512,'nodither');

for k = 1:20
k
imagesc(k*randn(20,20)),title(['B=' num2str(k)])
f = getframe;
im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
pause(1)
end
imwrite(im,map,'Test.gif','DelayTime',1)

Now my question is.. how do you retain the axis & ticks & x,y labels, & title?

Thank you if any of you can help.