Executing matlab script from static directory with current path as input in linux (as alias)

Hello everybody.
I am currently trying to execute a matlab script from a static directory with inputs from dynamic ones as an alias. Basically I manually change the directory to where the files (inputs) are and then execute a matlab script with an alias. This alias should include the current path as well as the execution of the script from a static directory.
My solution so far is:
matlab -nojvm -nodisplay -nosplash -batch path=pwd;run('/pathToScript/script');
When using this solution the "error message" always is zsh:unknown file attribute. Im relatively new to linux.
When using the above solution in two separate steps:
matlab -nojvm -nodisplay -nosplash path=pwd;
%in matlab environment
run('/pathToScript/script');
it works just fine. So basically using the alias to do both executions is just for reducing time.
Thanks

 채택된 답변

matlab -nojvm -nodisplay -nosplash -batch "path=pwd;run('/pathToScript/script');"
However I would suggest it would be safer to
matlab -nojvm -nodisplay -nosplash -batch "addpath(pwd);run('/pathToScript/script');"

댓글 수: 2

Thank you very much. This solves the problem of the execution of both commands. Do you know by any chance how to implement this in an alias? Using:
alias knock = 'matlab -nojvm -nodisplay -nosplash -batch "addpath(pwd);run('/pathToScript/script');"'
results in "Error: Invalid use of operator" for the "/" in /pathToScript. Somehow the " ' " is ended after run(' .
Thanks
alias knock="matlab -nojvm -nodisplay -nosplash -batch \"addpath(pwd);run(\\\"/pathToScript/script\\\");\""
It was tricky to get everything escaped just the right way.
At one level you are executing a shell command to create an alias. But the alias that is created has to be something that can be executed again, so you end up having to double-escape when building the alias.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2020년 5월 6일

댓글:

2020년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by