I'm trying to create a movie()
of a flickering checkerboard in matlab. I'm using the following code to create the frames:
close all;
n=80; % length of checkerboard squares in pixels
p=5; % number of checkerboard rows
q=6; % number of checkerboard columns
loops=100;
A=zeros(p*n,q*n,2);
my_checkerboard=logical(checkerboard(n,p,q));
A(:,:,1)=double(my_checkerboard(1:p*n,1:q*n));
A(:,:,2)=ones(p*n,q*n);
%A(:,:,2)=double(~my_checkerboard(1:p*n,1:q*n));
F(loops)=struct('cdata',[],'colormap',[]);
h=figure;
for ii=1:1000
figure(h);
imshow(A(:,:,mod(ii,2)+1));
drawnow;
F(ii)=getframe;
end
Now if I'm playing the movie like this
close all;
h=figure;
movie(h,F,1,10)
I will be able to scale the movie by drawing the corners of the figure. But if I'm scaling the figure before like this
close all;
h=figure('Position',[2640,280,960,800]);
movie(h,F,1,10)
the movie won't be scaled with the figure. Instead the movie will be played in the bottom left corner of the figure.
I got the feeling that this can be done by scaling not just the figure but also the axis, but I couldn't figure out, how to do it.
EDIT: I would also be happy, if someone could link me some resources on a gif generator or something, that can easily create a scalable flickering checkerboard with customizable numbers of tiles.
I think there is a bug in MATLAB movie
...
Following code works in most cases:
close all;
n=80; % length of checkerboard squares in pixels
p=5; % number of checkerboard rows
q=6; % number of checkerboard columns
loops=100;
A=zeros(p*n,q*n,2);
my_checkerboard=logical(checkerboard(n,p,q));
A(:,:,1)=double(my_checkerboard(1:p*n,1:q*n));
A(:,:,2)=ones(p*n,q*n);
%A(:,:,2)=double(~my_checkerboard(1:p*n,1:q*n));
F(loops)=struct('cdata',[],'colormap',[]);
h=figure;
for ii=1:10
figure(h);
%imshow(A(:,:,mod(ii,2)+1));
imshow(A(:,:,mod(ii,2)+1), 'Border', 'tight'); %Show image without borders
drawnow;
F(ii)=getframe;
end
savefig(h, 'h.fig') %Save the figure to a file, (not the best solution).
%Playing the movie
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all;
h = openfig('h.fig'); %Load the figure
% h=figure;
movie(h,F,1,10)
Saving and loading the figure, is just a simple way for keeping the dimensions of the original figure.