Running Matlab script from another directory

조회 수: 66 (최근 30일)
g
g 2019년 1월 22일
답변: Walter Roberson 2019년 1월 22일
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!

답변 (1개)

Walter Roberson
Walter Roberson 2019년 1월 22일
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.

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by