How to get the current running mlx filename?

조회 수: 17 (최근 30일)
Dorian
Dorian 2024년 10월 15일
편집: Gojo 2024년 10월 17일
Hi, I'm trying to obtain a livescript's filename during its execution...
I've tried using mfilename as it works for regular scripts but when I use it with a .mlx it outputs : "LiveEditorEvaluationHelperEXXXXXXXXXX" with X being a series of digits.
I've also tried using fileparts but it only works with an open file, and I don't necessarily want to open my scripts before running them.
Would anyone know a work-around or a different way of obtaining a livescript's name during its execution?
  댓글 수: 1
Rik
Rik 2024년 10월 15일
Unfortunately, as fas as I can tell, there is no general way.
You can use the editor to report the currently opened file, but that only works if the currently running live script is indeed the the active file in the editor.

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

채택된 답변

Gojo
Gojo 2024년 10월 15일
편집: Gojo 2024년 10월 17일
Hey Dorian,
As far as I understand, Live editors do not execute the .MLX script directly. For running the code, temporary files are created for the code section which are then evaluated and ran. Hence it is difficult to extract the file information in the case of Live Script. For more information, please refer to the following comment on a similar MATLAB Answers post: https://www.mathworks.com/matlabcentral/answers/9907-is-there-a-function-that-retrieves-the-filename-of-the-current-script#comment_759325
As you mentioned, you can use the fileparts function to get the name of the file when it is active (opened). However, since you mentioned that you may like to execute the live scripts without opening them, I would think that you could rather have it run as .M script. The mfilename function would run as expected if the script is run as .M file.
You can also programmatically convert the .MLX script into .M as mentioned in the following post: https://www.mathworks.com/matlabcentral/answers/271478-how-do-i-go-between-plain-scripts-m-and-live-scripts-mlx
However, for a more appropriate workaround, I would suggest you to raise a service request here: https://www.mathworks.com/support/contact_us.html?s_tid=hc_trail
I hope this helps!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Adding custom doc에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by