Is it possible to programmatically run and export a live function in MATLAB Version: 9.8.0.1323502 (R2020a)? I know in version 2022 you can use the export function.

14 ビュー (過去 30 日間)
I know that in Matlab 2022, you can use the function
export("MyLiveScript.mlx");
to export a Live Script or Function. But this doesn't work in Version 2020. Is there any work around, other than just clicking the menu bar?

採用された回答

Chandrika
Chandrika 2022 年 6 月 9 日
As per my understanding, you want to programatically execute and export a livescript. For MATLAB version R2020a, please look at the following commands as a possible workaround solution to run and export live function- MyLiveScript.mlx
mlxloc = fullfile(pwd,'\MyLiveScript.mlx');
fileout = fullfile(pwd,'\test.docx');
matlab.internal.liveeditor.executeAndSave(mlxloc);
matlab.internal.liveeditor.openAndConvert(mlxloc,fileout);
It shall convert the live script to a docx file and save it in the current folder. To save the output file, you can here use file extensions as per your convenience.
  2 件のコメント
Joe Lettieri
Joe Lettieri 2022 年 6 月 13 日
That looks like what I want to do. However, I get the following error:
Error using matlab.internal.liveeditor.LiveEditorUtilities.open>openUsingCEF (line 119)
Java exception occurred:
java.lang.RuntimeException: LiveCodeFileReader cannot find package to open
at com.mathworks.services.mlx.MlxFileUtils.nativeReadLiveCodeFile(Native Method)
at com.mathworks.services.mlx.MlxFileUtils.read(MlxFileUtils.java:60)
Error in matlab.internal.liveeditor.LiveEditorUtilities.open (line 31)
[javaRichDocument, cleanupObj, webWindow] = openUsingCEF(fileName, reuse, timeout, webWindow);
Error in matlab.internal.liveeditor.LiveEditorUtilities.openAndExecute (line 9)
[javaRichDocument, cleanupObj] = LiveEditorUtilities.open(fileName);
Error in matlab.internal.liveeditor.executeAndSave (line 20)
[javaRichDocument, cleanupObj, executionTime]= LiveEditorUtilities.openAndExecute(fileName); %#ok
Joe Lettieri
Joe Lettieri 2022 年 6 月 20 日
Yes, It works now. The problem was that I needed to call your code from a separate mfile! Thanks for the help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDirect Search についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by