1) How to hide some parts of the code
One way to publish parts of the code while hiding some other parts that you still want to execute, is to not include any code in the published document and add the code you want to be published as comments in the original M-file.
I attached publish_example.m to illustrate how you would go about that. To publish this file in PDF, use the following commands. We set the 'showCode' option to false so that none of the code gets published, and we'll have to add the code we want to see published as comments in the M-file.
>> options.format = 'pdf';
>> options.showCode = false;
The file contains two pieces of code. The first one is made of 3 lines (8-10) that display a figure:
t = 0:.1:pi*4;
y = sin(t);
Since 'showCode' is set to false, these three lines will not be published.
The second piece of code (lines 36-45) has been included in the comments in lines 19-34. Therefore, it is published.
You could use the same approach for your code, but you would have to copy and paste all the code you want to see published in a comment section.
Another approach would be to encapsulate the plotting code you want to hide in another script or function and call it from your published script. Something like:
In this case, instead of publishing all the plotting code, only the call to the plotting function would be published.
This will be less work than copying and pasting all your other code in comments, but it will show functionThatPlotsAFigure in the published document.
2) How to control the size of a figure published to a PDF
Unfortunately, it is currently not possible to change the size of figures published to a PDF file. You can change the size of figures that get published to HTML, but not PDF. This would be a nice enhancement. Thank you for your feedback.