2

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.

1
  • Not that I know of. But you could always run in -nodisplay mode, without the GUI all together. Commented Oct 28, 2012 at 18:48

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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.

Comments

0

You can also write close all after the plots, they will be plotted but instantaneously closed after. It is no clean but works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.