MATLAB getframe无法捕获所需的图像

时间:2014-05-18 07:41:39

标签: matlab

下面的代码来自“使用Matlab进行数值计算”。

我正在尝试捕获所有生成的点的图像(由于'erasemode','none'条件,matlab无法保存)。我已经尝试在while循环结束时放置F = getframe,并在while循环之后(按下停止按钮时),但所有这些都导致只捕获了一个点。

nmax = 100;
n = 2:nmax;
kappalo = n.^(1/2);
kappahi = 500*n.^3;

shg
clf reset
h = loglog(n,[kappalo; kappahi],'-',nmax,NaN,'.');
set(h(1:2),'color',[0 2/3 0]);
set(gca,'xtick',[2:2:10 20:20:nmax])
kappamax = 1.e6;
axis([2 nmax 2 kappamax])
stop = uicontrol('pos',[20 10 40 25], ...
   'style','toggle','string','stop','value',0);

h = h(3);
set(h,'erasemode','none','color','blue')
while get(stop,'value') ~= 1
   n = ceil(rand*nmax);
   A = randn(n,n);
   kappa = condest(A);
   set(h,'xdata',n,'ydata',kappa)
   drawnow            % Tried replacing drawnow with getframe
                      % Tried it here, after drawnow: F = getframe;
end

% Tried here, F = getframe; or F = getframe(gcf);


set(stop,'val',0,'string','close','callback','close(gcf)')

% Tried here.

1 个答案:

答案 0 :(得分:1)

似乎getframe忽略了erasemode属性。知道getframe重新渲染数字,它可能只是一个必须被接受的限制。不使用该属性,我得到了预期的结果。

nmax = 100;
n = 2:nmax;
kappalo = n.^(1/2);
kappahi = 500*n.^3;

shg
clf reset
h = loglog(n,[kappalo; kappahi],'-',nmax,NaN,'.');
set(h(1:2),'color',[0 2/3 0]);
set(gca,'xtick',[2:2:10 20:20:nmax])
kappamax = 1.e6;
axis([2 nmax 2 kappamax])
stop = uicontrol('pos',[20 10 40 25], ...
   'style','toggle','string','stop','value',0);

h = h(3);
set(h,'color','blue')
n=nan(10000,1);
kappa=nan(10000,1);
ix=1;
while get(stop,'value') ~= 1
   an = ceil(rand*nmax);
   A = randn(an,an);
   akappa = condest(A);
   n(ix)=an;
   kappa(ix)=akappa;
   set(h,'xdata',n,'ydata',kappa)
   drawnow            % Tried replacing drawnow with getframe
                         % Tried it here, after drawnow: F = getframe;
   ix=ix+1;
end
x=getframe;
set(stop,'val',0,'string','close','callback','close(gcf)')