Krys 0 Posted December 12, 2014 · Report post Здравствуйте. Подскажите, пожалуйста, как в скрипте Matlab узнать папку, в которой этот самый скрипт находится? Внутри скрипта используются относительные пути в предположении, что скрипт находится в текущей папке, т.к. он когда-то был главным скриптом проекта. Но потребовалось этот скрипт вызывать из другого скрипта другого проекта. И теперь текущая папка указывает на положение вызывающего скрипта, соответственно в вызываемом не срабатывают пути. Нужно как-то сделать так, чтобы независимо от текущей папки, пути внутри скрипта были указаны относительно положения файла этого самого скрипта. Quote Ответить с цитированием Share this post Link to post Share on other sites
spbroma 0 Posted December 12, 2014 · Report post mfilename('fullpath') Quote Ответить с цитированием Share this post Link to post Share on other sites
Krys 0 Posted December 15, 2014 · Report post Большое спасибо Quote Ответить с цитированием Share this post Link to post Share on other sites
Krys 0 Posted January 14 · Report post Здравствуйте. Пришла пора повторить вопрос, только для файлов *.mlx (live script, live editor). Версия матлаба 2016b. Не могу найти решение. Гуглил, вот очень близкая проблема: I'm working on my MATLAB code in a number of different locations, and it would be really helpful if I could make the code aware of its location on the computer. Till now I worked with .m-files. For .m-files I found the following solutions: %example 1 cd(fileparts(mfilename('fullpath'))) or %example 2 tmp = matlab.desktop.editor.getActive; cd(fileparts(tmp.Filename)); or %example 3 S = dbstack('-completenames'); S(1).file or %example 4 which(mfilename) ... Outputs of the examples above executed in a *.mlx-file: %example1: mfilename returns the path to the 'MatlabEvaluationHelper' in the 'AppData\Local\Temp'-folder %example2: output is an empty array %example3: same output as example1 %example4: same output as example1, because mfilename returns "MatlabEvaluationHelper" Quote Ответить с цитированием Share this post Link to post Share on other sites
Krys 0 Posted March 1 · Report post 14.01.2022 в 14:25, Krys сказал: Версия матлаба 2016b. Не могу найти решение. Сам себе отвечу: перешёл на версию 2021b update 1, там это заработало matlab.desktop.editor.getActive Quote Ответить с цитированием Share this post Link to post Share on other sites