Determine own location in a live script
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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).
3 Kommentare
Qi Wang
am 3 Mär. 2021
Following trick works for me (R2020b):
fileparts(matlab.desktop.editor.getActiveFilename)
Reno Filla
am 1 Okt. 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().
Antworten (1)
Rik
am 25 Jan. 2019
Bearbeitet: Rik
am 3 Mär. 2021
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.
Edit:
fileparts(matlab.desktop.editor.getActiveFilename)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!