How to fold up code in live script?

93 ビュー (過去 30 日間)
Pierre Lonfat
Pierre Lonfat 2018 年 4 月 6 日
コメント済み: Jared MacDonald 2020 年 3 月 3 日
Dear all,
Insert section break is easy but I still don't know how to fold up the code like %% would do it in regular script.
Thanks in advance and have a nice day,
Pierre
  1 件のコメント
XJ_CHEN
XJ_CHEN 2018 年 8 月 28 日
Yes I have the same problem.

サインインしてコメントする。

採用された回答

Chris
Chris 2018 年 9 月 6 日
This isn't a feature for live scripts right now, but if you would like to see it please consider submitting an enhancement request through tech support. If you just need a workaround, here is what tech support suggested:
1. Convert to M file and "publish" with 'showcode' as false. First, convert the Live Script into an M file. You can do this interactively by clicking "Save As" and then choosing the "M" file option in the File Type section or you can do it programmatically as follows:
>> matlab.internal.liveeditor.openAndConvert('live_script_to_be_converted.mlx', 'output_script.m');
Once you have the converted M file which has all the section breaks and formatting, you can use the "publish" function as follows from the MATLAB Command Window:
>> options.format = 'pdf';
>> options.showCode = false;
>> publish('output_script.m',options)
This will publish the PDF file to a sub-directory called "html" inside the current working directory.
Here is a documentation link for the "publish" function and specifically, the "showCode" option:
Please note, when saving the MLX file as M file and then publishing, it does not convert the LaTeX expressions to something readable. It also automatically inserts a table of contents at the beginning.
2. Encapsulate the code in another script or function. An alternate approach would be for you to encapsulate the code you want to hide in another script or function and call it from your published Live Script. For example, 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.
3. Publish the Live Script as an HTML and then modify the HTML page to hide the code sections and then publish it as a PDF.
The options stated above are simply workarounds as we do not currently have this functionality. A request has been submitted to our developers to add in this feature and they are considering this for future releases of MATLAB. We appreciate your feedback as we constantly strive to improve our products.
  1 件のコメント
busranur davuter
busranur davuter 2019 年 1 月 26 日
Thank u correct reply :)

サインインしてコメントする。

その他の回答 (2 件)

Kevin Chng
Kevin Chng 2019 年 3 月 27 日
Untitled.png
In 2019a, it allows you to hide the code before exporting.
  3 件のコメント
Andri Bezzola
Andri Bezzola 2019 年 7 月 30 日
yes, please? anyone know how to unhide code?
Jared MacDonald
Jared MacDonald 2020 年 3 月 3 日
To unhide the code, click one of the other view buttons, "output on right" or "output inline".

サインインしてコメントする。


Prajit T R
Prajit T R 2018 年 4 月 10 日
  1 件のコメント
Pierre Lonfat
Pierre Lonfat 2018 年 4 月 11 日
Unfortunately this doesn't work on live script :/ ... Thank you anyway !

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLive Scripts and Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by