Programmatically run and export live script
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I have a set of live scripts that I can save as html and publish for a client to inspect. Right now, I do that by opening one script at a time, hitting F5, and then clicking Save As >> html to save it. I'd like to automate that process. I was hoping publish('script.mlx','html') would work, but it doesn't seem to. I can save the *.mlx as .m and publish that, but it changes the layout and formatting, and I'd like to keep those.
採用された回答
Baptiste Ottino
2017 年 8 月 7 日
Hi, I'm late to the party, but I spent hours and hours on this issue, and by pure luck I just found the answer. So in hope someone reads this, here is the function you are looking for. It certainly is the one called by the "Save As" button.
doc matlab.internal.richeditor.openAndConvert
Best regards.
13 件のコメント
In R2017a it is:
matlab.internal.liveeditor.openAndConvert(inputFile, outputFile);
Baptiste Ottino
2017 年 8 月 11 日
Thanks. I should have wirtten that I use R2016b.
Toby Driscoll
2017 年 12 月 7 日
This is a great tip! But while I get the liveeditor.openAndConvert to run fine in 2017b, the richeditor version leads to a command-not-found error.
Christopher Coello
2018 年 9 月 17 日
Have tried to find this solution for long... Thanks Baptiste, works like a charm on 2017b.
Simon Parten
2019 年 1 月 10 日
Rich editor renamed to liveeditor I think from 2017b onwards.
Timothy Koehler
2019 年 9 月 27 日
That option does work for saving the live script. The LiveScripts save their state, though, so in order to programmatically update them, I would think to use the following two commands:
matlab.internal.liveeditor.executeAndSave(filename);
matlab.internal.liveeditor.openAndConvert(filename,'report.pdf');
The second command works fine, but the first command yields:
Error using matlab.internal.liveeditor.LiveEditorUtilities.execute (line 12)
Java exception occurred:
java.io.IOException: java.lang.RuntimeException: LIveCodeFileReader cannot find package to open
at com.mathworks.services.mlx.MlxFileUtils.getCode(MlxFileUtils.java:183)
Any advice, or is there an alternate way to execute the live script?
Jianyong Wen
2019 年 11 月 8 日
編集済み: Jianyong Wen
2019 年 11 月 8 日
try this way:
import matlab.internal.liveeditor.LiveEditorUtilities
[javaRichDocument, cleanupObj, executionTime] = LiveEditorUtilities.openAndExecute(which(filename));
LiveEditorUtilities.saveas(javaRichDocument, 'report.pdf');
Timothy Koehler
2019 年 11 月 8 日
That option resulted in a timeout when trying to run the saveas() function.
However; you gave me a path to the right solution! If I simply use:
matlab.internal.liveeditor.executeAndSave(which(filename));
instead of
matlab.internal.liveeditor.executeAndSave(filename);
, then the executeAndSave command will work. Apparently, it needs the full path to the .mlx file. Once that command completes, the openAndConvert() function works properly to generate the report.
Thanks for putting me on the right path.
Jana Pecke
2020 年 10 月 26 日
hallo everybody,
i tried this in Matlab 2020a:
matlab.internal.liveeditor.executeAndSave(which('Handout.mlx'));
matlab.internal.liveeditor.openAndConvert('Handout.mlx', 'test.pdf');
but i get every time a pdf with my designed live script as well the code.
Do you have an idea, why this function also plot the code?
Jared Augsburger
2020 年 11 月 4 日
編集済み: Jared Augsburger
2020 年 11 月 4 日
See the bottom section of this documenation (Share Live Scripts and Functions). While it doesn't describe how to programatically control the plotting of the code, it does describe how to do this using the live script GUI.
You can use:
mlxloc = strcat(pwd,'\filename.mlx');
fileout = strcat(pwd,'\example.docx');
matlab.internal.liveeditor.openAndConvert(mlxloc,fileout);
Andrew Janke
2021 年 4 月 21 日
You da bomb! This helped me out a lot.
Harry van der Pol
2022 年 1 月 9 日
編集済み: Harry van der Pol
2022 年 1 月 9 日
As an addition to the answer of Jesse Desterro
In stead of using strcat, use the function fullfile to make the script run as well on Window like systems as on Unix systems. So instead of
mlxloc = strcat(pwd,'\filename.mlx');
use
mlxloc = fullfile(pwd,'filename.mlx');
その他の回答 (1 件)
export("myscript.mlx")
NOTE: if run this in GITHUB hosted runner, some problem may happen
カテゴリ
ヘルプ センター および File Exchange で Live Scripts and Functions についてさらに検索
製品
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
