【问题标题】:Why Low Memory Make Colorbar Unresponsive in Matlab Figures?为什么内存不足会使 Matlab 图形中的颜色条无响应?
【发布时间】:2016-07-21 16:48:53
【问题描述】:

条件:如果循环运行没有停顿,颜色条不会占图片的 50% 左右;如果我设置断点并逐步运行,所有颜色条都会出现;我认为这是一些稳定性/内存问题

伪代码

i=1;
while (i < 3);

    figure('Visible', 'off');
    hax=axes();
    image('Parent',hax);

    % Do heavy computation here; see the warning below for it. 
    a=rand(1,20000); 
    b=rand(1,20000);
    C=rand(20000,20000);     
    imagesc(a,b,C);
    colorbar(hax)        

    %% Unsuccessful attempts
    %drawnow % does not help
    %pause(1) % does not help

    homedir=char(java.lang.System.getProperty('user.home')); % all systems
    filename=fullfile(home, sprintf('/Desktop/%d', i));
    export_fig(filename, '-png', '-q101', '-a1', '-m1', ...
        '-CMYK', '-nocrop', '-dpng', hax);

    i=i+1;

end

颜色条消失后的错误消息,表示内存问题

Warning: print2array generating a 46.1M pixel image.
This could be slow and might also cause memory
problems.
  • 苏弗。 colorbar 之后的命令 drawnow 没有帮助。

系统:Linux Ubuntu 16.04 64 位
Matlab:2016a
硬件:Macbook Air 2013-mid

【问题讨论】:

  • 在您致电colorbar 后添加drawnow。问题是如果没有暂停,渲染器就没有时间将颜色条实际绘制到屏幕上。
  • 给我们一个minimal reproducible example,它实际上证明了这个问题。除非您真的只想显示默认的 image,否则编写的代码是无法运行的。
  • 您似乎忘记使用实际代码编辑问题。我们不想要伪代码,因为它不会重现问题。
  • 在创建图像和颜色条时尝试指定明确的轴
  • 再次向我们展示实际代码。您提供的代码没有任何内存问题。

标签: matlab memory


【解决方案1】:

这是 Matlab 的内部问题。如果内存不足,某些组件的计算和图形会变得不稳定,因为封闭的系统,我无法分析和理解。 只需使用具有困难矩阵计算的真实数据来重现错误。 如线程How to Allocate More Space to Swap and Increase its Size Greater than Ram? 中所述,我使用交换扩展内存从 8 GB 到 36 GB,现在没有错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 2018-04-04
    • 1970-01-01
    • 2018-10-28
    相关资源
    最近更新 更多