Programmatically run and export live script
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
7 개 추천
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);
Thanks. I should have wirtten that I use R2016b.
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.
Have tried to find this solution for long... Thanks Baptiste, works like a charm on 2017b.
Rich editor renamed to liveeditor I think from 2017b onwards.
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');
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.
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);
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
