Running Matlab script from another directory

57 views (last 30 days)
g
g on 22 Jan 2019
Answered: Walter Roberson on 22 Jan 2019
I currently have a script with the following line. What it does is opens matlab and passes the file to mymatlabscript, then exits once the calculation is done.
matlab -nodesktop -nodisplay -r "try; existing_file = '$existfile'; mymatlabscript; end; exit"
I want to be able to run this script from another directory, outside of the directory that contains mymatlabscript and the script with the line above. How should I configure this line to be able to do that? Assume the other directory does not have mymatlabscript. Thanks!

Answers (1)

Walter Roberson
Walter Roberson on 22 Jan 2019
If it is truly a script and not a function, then you would typically use run() naming the script file. However, that will cd to the directory containing the file and cd back afterwards, which might not be suitable for your needs, so you might prefer to start with addpath() the directory that the script is in.

Categories

Find more on Search Path 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!