Stop some code from Publishing

조회 수: 48 (최근 30일)
Richard
Richard 2014년 10월 22일
댓글: Allison 2023년 11월 11일
Hello,
I am looking for a control that lets me choose what gets published when using MATLABs publish feature.
For example:
1) I want to block all the plotting code in my .m file from getting published to a pdf. How can I do this?
2) I want to control the size of the figure that get placed in a pdf. I know the figures created in html output are proportional to the size you create in your code, but the pdf figured appear to be predetermined and are rather small.
Thanks, Rich

답변 (2개)

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014년 10월 23일
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;
>> publish('publish_example.m',options)
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);
plot(t,y);
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:
%%Now plot a figure
functionThatPlotsAFigure
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.
  댓글 수: 1
Allison
Allison 2023년 11월 11일
I agree, please please make it possible to change figure sizes published to pdf. I wasted so much time on this until I finally saw your post.

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2018년 1월 18일
If there are only a minority of lines of code that you want to hide, I would first publish as HTML. It's easy enough to edit those lines out of the HTML file. Then convert the resulting file to PDF.

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by