在播放电影之前缩放movie()的输出

时间:2019-10-11 09:54:56

标签: matlab animation matlab-figure

我正在尝试在matlab中创建一个闪烁的棋盘格movie()。我正在使用以下代码创建框架:

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

现在,如果我正在播放这样的电影

close all;
h=figure;
movie(h,F,1,10)

我将能够通过绘制图形的角来缩放影片。但是,如果我像这样以前缩放数字

close all;
h=figure('Position',[2640,280,960,800]);
movie(h,F,1,10)

电影不会按照人物比例缩放。相反,电影将在图的左下角播放。
我感觉这不仅可以缩放图形,还可以缩放轴,但是我不知道该怎么做。

编辑:如果有人可以将gif生成器上的某些资源链接到我,我也将很高兴,它可以轻松地创建具有可定制数量的图块的可扩展的闪烁棋盘。

1 个答案:

答案 0 :(得分:1)

我认为MATLAB movie ...中有一个错误

以下代码在大多数情况下有效:

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)

保存和加载图形只是保持原始图形尺寸的一种简单方法。