Programmatically determine if publishing or executing a script

Prior to the release of R2016a, publishing is a way in MATLAB to document the results of a script. I find that when I run the script manually, I often place commands pausethroughout my script. Is there an easy way to determine if a script is being published or not? Then I can wrap my pauses as code:

if isNotPublishing
    pause();
end

My google foo did not help me find a solution to this.

+4
source share
1 answer

- , publish . dbstack struct, , , , dbstack. name, , publish. , , script publish.

stack = dbstack;
isBeingPublished = ismember('publish', {stack.name});

, ,

isBeingPublished = ismember('publish', cellfun(@(x)x.name, dbstack, 'UniformOutput', 0));

, script

publish('myscript.m')

, pause ( , mypause), . , pause dbstack - publish, script, publish. , mypause().

function mypause(varargin)
    stack = dbstack;
    if ~ismember('publish', {stack.name});
        builtin('pause', varargin{:})
    end
end
+5

All Articles