Is it possible to PUBLISH a script that includes headings within FOR-loops with MATLAB?

3 views (last 30 days)
I would like to publish a script with headings within a FOR-loop, but I cannot seem to. For instance, publishing the script:
%%Heading 1
for n = 1:10
%%Heading 2
disp(num2str(n));
end
shows "Heading 2" as a comment, not a heading. If I modify the script to be:
%%Heading 1
for n = 1:10
%%Heading 2
disp(num2str(n));
end
then the heading shows up, but it results in the error:
Error: At least one END is missing: the statement may begin here.
within my HTML document, instead of the script's output.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This enhancement has been incorporated in Release 2008a (R2008a). For previous product releases, read below for any possible workarounds:
If you can omit the script output, you can suppress code evaluation using the "evalCode" option to PUBLISH.
opt = struct;
opt.evalCode = false
publish('foo.m', opt);
where "foo" is the script to be published. This will result in the creation of an HTML-file that breaks the source code according to unindented headings (as in the second example, above), but does not include the error nor the output of evaluating the code.
Another option is to create a second script which includes the commands originally located within the FOR-loop, and publish these two scripts separately.

More Answers (0)

Categories

Find more on Programming Utilities in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!