Determine own location in a live script

56 views (last 30 days)
Stephen Bruder
Stephen Bruder on 25 Jan 2019
Commented: Reno Filla on 1 Oct 2021
Using live script: How do I make the live script aware of (or determine) its own file location? This is a simple task with a *.m file script. This causes problems when using a live script to call/run other scripts/simulink-files located in the same folder (as the live script) as the "current folder" is not updated to the live script's location (as is the case in a *.m file).
Reno Filla
Reno Filla on 1 Oct 2021
Thanks Qi Wang, this is a live saver! I was getting crazy that Live Script would only get me "LiveEditorEvaluationHelpExxxxx" as reply to mfilename().

Sign in to comment.

Answers (1)

Rik on 25 Jan 2019
Edited: Rik on 3 Mar 2021
I see no indication that pwd doesn't work in live-scripts.
If you can't guarantee the current folder, but do know the file name, you can use which.
dbstack doesn't seem to work as expected in my tests.
There is also another thing you could try, @Qi Wang suggested using this:
Rik on 3 Mar 2021
I added it to my answer to prevent it from disappearing into the older comments.

Sign in to comment.


Find more on Live Scripts and Functions in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!