views:

146

answers:

3

I am using the publishing functionality of MATLAB to generate a quick report of some analysis I'm running. Since the analysis is quite time-consuming, I've added a progress bar to keep track of how long is remaining. The problem is that I'd prefer this progress bar not to appear in my report.

Is there a way to keep MATLAB from introducing some content in a published document. Or, alternatively, is there a way I can know I'm currently in publish mode, so I can skip the progress bar in those cases?

Edit: There's a couple of solutions already, but I'd prefer something automatic that doesn't require an extra step in the workspace before publication. Any other tricks?

+1  A: 

AFAIK there is no way of excluding parts from published document.

Perhaps what you can do is to output a unique pattern (BEGIN/END) around the progress bar code, which you will then parse the html file and remove those sections using some script.

Amro
I guess that would work, but I'd prefer to avoid the extra step. I'll keep looking for a more elegant solution, but thanks!
Kena
+1  A: 

I'm assuming you're using the WAITBAR function to generate a progress bar, and you have only one of these waitbars in your function.

Before you publish the file pre-create the waitbar:

h = waitbar(0);

Then make the waitbar invisible to the PUBLISH function:

set(h,'HandleVisibility','off')

Where you use the waitbar in your code, you have to specify that you want to reuse the hidden waitbar by referring to it again, with the handle, h:

waitbar(newPercentage,h);

see the function reference page for waitbar for more help.

Mike Katz
Sounds nice, but doesn't seem to work for me. The waitbar still appears... Will investigate
Kena
Works if I set 'Visible' to off too, which is not perfect, but acceptable
Kena
A: 

Another slightly more generic option (inspired by Mike Katz' response), which works for any kind of content you don't want (or explicitly want) to include in your report.

in your module/function

try
   inPublishMode = evalin('base', 'inPublish');
catch
   inPublishMode = false;
end

You can now set the inPublish variable from the workspace before running your test, and wrap your optional code in conditional statements.

if inPublishMode
    % do something
end

Still not perfectly satisfactory, but it's another tool in the bag.

Kena

related questions