Export function is saving previous result of matlab live script

조회 수: 11 (최근 30일)
Prathyusha Gurrampally
Prathyusha Gurrampally 2024년 8월 5일
편집: Pavan Sahith 2024년 8월 6일
Export function is saving previous result of matlab live script, and saving it is loosing all the data when overwritten.
I have a matlab live script file, and export function is included in that, however it is not saving the current run data.
is there any way to export the only data of the current state of matlab live script?

답변 (2개)

Pavan Sahith
Pavan Sahith 2024년 8월 5일
편집: Pavan Sahith 2024년 8월 5일
The “export()” function takes a file path as argument and therefore, it loads the last saved state of the file from disk for the export. So the results are not current. If the most recent execution results should be considered while exporting, please save the file before exporting.
You can also do it programatically, Here is an example :
global scripts_dir_ul script_name
input_file = fullfile(scripts_dir_ul, script_name); % Path to the current running .mlx file
output_file = "Test_" + string(datetime('now', 'Format', 'yyyy-MM-dd_HH_mm_ss')) + "_report.pdf";
% Save the live script
matlab.internal.liveeditor.executeAndSave(which(input_file));
% Export the PDF file
matlab.internal.liveeditor.openAndConvert(which(input_file), fullfile(scripts_dir_ul, output_file));
disp(['Report exported to: ', fullfile(scripts_dir_ul, output_file)]);
  • matlab.internal.liveeditor.executeAndSave(which(input_file));: This function ensures the live script is saved with the latest data before any export operations. The which function provides the full path to the .mlx file, which is necessary for the executeAndSave function to work correctly.
  • matlab.internal.liveeditor.openAndConvert(which(input_file), fullfile(scripts_dir_ul, output_file));: This function opens the saved live script and converts it to the desired format (PDF in this case).
You can refer to following links to know more
  댓글 수: 2
Prathyusha Gurrampally
Prathyusha Gurrampally 2024년 8월 5일
Hi Pavan,
I am facing the below issue while using this method
Nested Live Editor execution is not supported.
executionTime = matlab.internal.liveeditor.LiveEditorUtilities.execute(editorObj.Editor.RtcId, fileNameToExecute);
matlab.internal.liveeditor.executeAndSave(which(input_file));
Pavan Sahith
Pavan Sahith 2024년 8월 5일
편집: Pavan Sahith 2024년 8월 6일
I tried with a sample code in MATLAB R2023a and I don't face any issue with nested Live Script execution.
However, I noticed a thread where a user highlighted that she faced a similar issue, noting "Nested Live Editor execution is not supported" in MATLAB starting from version R2023b and onwards.
To work around this limitation, try running this code form a .m file,which might avoid the nested execution issue.

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


Yukthi S
Yukthi S 2024년 8월 5일
  댓글 수: 3
Yukthi S
Yukthi S 2024년 8월 5일
편집: Yukthi S 2024년 8월 5일
Try using
save(input_file)
instead of
save(inputfile)
Prathyusha Gurrampally
Prathyusha Gurrampally 2024년 8월 5일
Hi Yukthi,
Sorry, its a typo in the above code, However, i am trying to save using ' save(input_file) '

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

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

태그

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by