【问题标题】:MATLAB getframe not capturing desired imageMATLAB getframe 未捕获所需的图像
【发布时间】:2014-05-18 07:41:38
【问题描述】:

以下代码来自“Numerical Computing with Matlab”。

我正在尝试捕获生成的所有点的图像(由于 'erasemode','none' 条件,matlab 无法保存)。我尝试将 F=getframe 放在 while 循环的末尾和 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.

【问题讨论】:

    标签: matlab


    【解决方案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)')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多