Live script change context to current directory (same behavior as normal m files)
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Pierre McGrail
il 12 Set 2022
Commentato: Pierre McGrail
il 22 Ago 2023
Hi, is there any way to configure MATLAB so live scripts change to current directory when they are executed ? I am looking for the same behavior as .m file which ask to change the directory when they are executed.
Right now, I have to add some code to do that (see https://www.mathworks.com/matlabcentral/answers/416718-automatically-add-an-opened-live-script-s-directory-to-the-search-path-for-the-current-session)
Basically, the reason to change context is to be able to load some data files which are in the same dir as the mlx script. I want to use a relative path and don't want to use an absolute path.
0 Commenti
Risposta accettata
Walter Roberson
il 12 Set 2022
No, no way is provided to configure Live Scripts to change directories (or ask to change directories) when invoked while the current directory is not the place the Live Script is stored.
When you execute a Live Script from the command prompt or the editor window, the first thing it does is create a new temporary file containing only the MATLAB code, omitting any controls, text, images and so on that you annotated the code with. It then executes the temporary file.
Because of this, it is normal for Live Script files to not really be executed from where they are stored... and Mathworks did not think to put in such a test themselves.
You will therefore have to use the kind of code tricks that you pointed out through that link.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!