Automatically add an opened live script's directory to the search path for the current session
Is there a way to automatically add an opened Live Script's directory to the search path for the session?
Desired behavior:
- Open file browser, navigate to directory where Live Script resides
- Double click on Live Script, which opens up MATLAB
- Either: (a) the directory where the Live Script file lives is listed as the "current directory" or (b) the directory where the Live Script file lives is added to the search path for the current session.
Use case:
I'll be sharing Live Scripts demoing concepts with my students. Some of these will load .mat files that I will also share with them. If the students just download the attachments from my e-mail into some random directory and run it, the Live Script won't be able to find the .mat files to load.
Comments:
For normal scripts (.m files), I can force change the directory with
cd(fileparts(which(mfilename)));
But running mfilename on a Live Script gives not the expected answer:
ans = 'LiveEditorEvaluationHelperE976215442'
and I would appreciate a Live Script specific answer.
Answers (1)
2 Comments
Categories
Find more on File Operations 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!