在Matlab中禁用绘图 [英] Disable plots in Matlab

查看:831
本文介绍了在Matlab中禁用绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些用Matlab编写的程序,出于某些原因(调试,使用不同的输入进行测试等),我需要运行几次

I have some programs written in Matlab that I need to run several times for some reasons (debugging, testing with different input, etc...)

但是,程序及其各种功能绘制了很多图形,因此每次我运行该程序时,我都必须等待所有图形显示出来,这非常烦人且耗时(尤其是当您使用小型笔记本电脑时). 程序执行后,我用close all关闭它们.

But, there are a lot's of graphs that are plotted by the programs and its various functions such that everytime I run the program, I have to wait for all the graphs to be displayed, which is very annoying and time consuming (especially when you are working with a small laptop). After the program is executed, I close them with a close all.

所以我的问题是:

是否可以在选项中或通过执行某些代码(如disable plotenable plot)以确保没有数字来禁用Matlab中的所有绘图/图形/图形?正在显示.

Is there a way to disable all plots/figures/graphs in Matlab? either in the options, or by executing a certain code like disable plot and enable plot to ensure that no figures are being displayed.

我知道我可以浏览代码并注释绘图部分,但是我不想忘记取消注释.

I know that I can just browse the code and comment the plotting part, but I don't want to forget to uncomment.

推荐答案

尝试将这两个命令组合使用:

Try some combination of the two commands:

set(gcf,'Visible','off')              % turns current figure "off"
set(0,'DefaultFigureVisible','off');  % all subsequent figures "off"

第二个,如果将其放在程序的开头附近,可能会帮到您.当然,它仍在创建绘图,这对于计算时间和/或RAM问题可能是不希望的.

The second one, if you put it near the beginning of your program, might do the trick for you. Of course, it is still creating the plots, which might be undesirable for computation time and/or RAM issues.

这是一个可以避免使用Matlab的经典原因.它会导致不良的程序设计.为了正确解决此问题,您应该创建一些东西,使您可以在程序的最高级别翻转开关",并控制是否显示图.也许它甚至具有显示/不显示"选项的等级,因此您可以根据运行的诊断程序选择不显示/不显示的不同类型的图.

This is a classic reason to avoid Matlab when one can. It fosters bad programming design. To solve this problem correctly, you should create something that lets you "flip a switch" at the highest level of your program and control whether plots show or do not show. Perhaps it even has gradations of the show/don't show option so you can select different types of plots that do/do not show depending on what diagnostics you are running.

理想情况下,您希望此翻转开关"创建为可访问其他对象的可见性和绘图功能的类.但是,由于在Matlab中交互式面向对象非常麻烦,因此开发这种解决方案通常不值得付出努力,而且大多数人从他们的项目开始就就没有考虑过这一设计方面.

Ideally, you'd want this "flip a switch" creation to be a class that has access to visibility and plot functions of other objects. But because interactive object-orientation is so cumbersome in Matlab, it's often not worth the effort to develop such a solution, and most people don't think about this design aspect from the outset of their project.

Matlab会鼓励人们通过制作诸如"isPlotVisible"之类的标志变量并创建始终接受此类标志的函数来解决此问题.我同意这是一个糟糕的设计.

Matlab would encourage someone to solve this by making flag variables like "isPlotVisible" or something, and creating functions that always accept such flags. I agree this is a bad design.

这篇关于在Matlab中禁用绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆