Reputation: 249
Is there any function to avoid plot outputs of a m-file?
I mean I place a function ( like clc) on the beginning of a file and then all plot functions are blocked.
Upvotes: 2
Views: 103
Reputation: 478
I don't know about a single command that does this, but you could accomplish with a small extra bit of code.
% Declare a variable for skipping at the top of your .m file
skip = 1; %example, 1 = skip, 0 = plot
% do things....
% Then nest your plot commands
if (skip == 0) % wants to plot in this case
% Whatever plot code in here
plot(x,y);
end
That should do the trick, though I realize it isn't quite a clean, single function like you requested. I hope it helps! :)
Also, I understand that if you're not necessarily working with your own .m files, or the script is very long, this may not be practical.
Upvotes: 1
Reputation: 1445
You can make all matlab plots invisible with:
set(0, 'DefaultFigureVisible', 'off');
Changing off
to on
reverses the process (which you'll probably need to do because this will switch off all your plots!)
You could add that line to the start of your m-file, and then add
close all;
set(0, 'DefaultFigureVisible', 'on');
to the end.
Upvotes: 1
Reputation: 11168
You can overload the built-in plot function with your own (nested inside your function or in the same directory):
function myfun(a,b)
plotting = false;
plot(a,b);
plot(b,a);
function varargout = plot(varargin)
if plotting
[varargout{1:nargout}] = builtin('plot',varargin{:});
end
end
end
Nothing will happen when you call myfun
, unless you change plotting=false
of course.
Extra info on overloading built-in functions: http://www.mathworks.nl/support/solutions/en/data/1-18T0R/index.html?product=ML&solution=1-18T0R
Upvotes: 1
Reputation: 35525
You can also write close all
after the plots, they will be plotted but instantaneously closed after. It is no clean but works.
Upvotes: 0