【问题标题】:How to turn off figure display while running plot scripts如何在运行绘图脚本时关闭图形显示
【发布时间】:2015-08-06 11:34:00
【问题描述】:

我创建了几个条形图和散点脚本来绘制我的数据。问题是 Matlab 在创建绘图时显示每个绘图,使事情变得非常具有破坏性(在绘图完成之前我不能做任何其他事情)。我尝试了在 Mathworks.com 和 here on Stack Exchange 上发布的几种方法,但没有一种方法有效。这是我的散点代码示例:

fig = figure(456);
scatter(Data(:,1),Data(:,2),'filled');
hold on;         
h = plot(Data(:,1),b,'-');
legend(h,sprintf('r = %s, p = %s',num2str(r),num2str(p)));
title(sprintf(<plot title>));
xlabel(sprintf('%s',set1.textdata{1,z+2}));
ylabel(sprintf('%s',set2.textdata{1,f+2}));
hold off
set(findall(fig,'type','text'),'fontSize',16,'fontweight','bold')
saveas(figure(456),fullfile(output_path, sprintf(<filename>));
close(fig)

有人可以帮忙吗?非常感谢!

【问题讨论】:

    标签: matlab plot figure


    【解决方案1】:

    好的,这应该可以了:

    fig = figure('Visible', 'off');
    scatter(Data(:,1),Data(:,2),'filled');
    hold on;         
    h = plot(Data(:,1),b,'-');
    legend(h,sprintf('r = %s, p = %s',num2str(r),num2str(p)));
    title(sprintf(<plot title>));
    xlabel(sprintf('%s',set1.textdata{1,z+2}));
    ylabel(sprintf('%s',set2.textdata{1,f+2}));
    hold off
    set(findall(fig,'type','text'),'fontSize',16,'fontweight','bold')
    saveas(fig,fullfile(output_path, sprintf(<filename>));
    close(fig)
    

    【讨论】:

    • OP 提到他/她已经尝试了此页面上的所有答案:stackoverflow.com/questions/10129622/disable-plots-in-matlab - 并且您提供的答案已包含在内......现在您的建议 应该 工作,所以我真的很困惑为什么它不工作。
    • 我假设 OP 尝试过:fig = figure(456); set(gcf,'Visible','off'); 这仍然会让它们弹出。否则,它必须工作。正确的? :-)
    • 使用fig = figure(456, 'Visible','off'); 我得到这个错误:输入参数太多。使用fig = figure(456); set(gcf,'Visible','off'); 并没有阻止数字弹出。
    • 是的,我仍然不清楚你怎么能做到这两个 - 在一行中设置图形编号和其他图形属性,因为我认为你不能这样做 figure('Number',492) . Number 是只读属性。但是,只要您在此代码之后立即关闭图形,就没有必要将其设置为特定数字。唉,我在这台机器上没有 Matlab 许可证可以玩。
    • 你是对的,Matlab 不允许设置图形编号然后声明图形属性。数字确实不是必需的,所以你的答案很好。即使没有使用 Matlab,您也能回答我的问题真是太好了。
    猜你喜欢
    • 2018-04-27
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多