필터 지우기
필터 지우기

How to change directory of matlab script in linux command line

조회 수: 9 (최근 30일)
jan mischke
jan mischke 2015년 11월 2일
편집: Bora Eryilmaz 2015년 11월 13일
I need to open matlab from a linux workspace and let it run a cript. The problem is, that my script is not in the home directory and I can't put it there. What I need to figure out is how to change the command so it will automatically run the script in the right directory.
matlab -nodisplay -r script.m
This command wont work because it wont find the script. Is there a way like
matlab -nodisplay -r ../test/test/test/script.m
to use something like that? It is hard to explain but I need to get it to work with a linux command (so no addpath or something like that possible). Thank you very much
  댓글 수: 2
jan mischke
jan mischke 2015년 11월 4일
I got another question to that...Is it possible to run two different scripts with the command line? I tried things like
matlab -nodisplay -r script1; script2;
but it wouldn't work. Right now I can just open matlab, run the script, close matlab and open it again to run the second script. Opening and closing matlab is very time consuming though. Is there a better way to run the second script without closing and reopening matlab? Thank you
Bora Eryilmaz
Bora Eryilmaz 2015년 11월 13일
편집: Bora Eryilmaz 2015년 11월 13일
You are just missing quotes after the -r flag. As long as the two scripts are on your path, you can run both with a single command:
matlab -nodisplay -r "script1; script1"
If you know the absolute path of these scripts, you can also add the "cd" command:
matlab -nodisplay -r "cd('/home/username/matlab...'); script1; script1"

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2015년 11월 2일
matlab -nodisplay -r "try; run('../test/test/test/script.m'); catch ME; end; quit();"
Note:
  1. run() only applies to scripts, not functions.
  2. run internally cd's until the script is in the current directory. If the script needs to access files in the directory you start matlab from, then this is not the appropriate solution.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by