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 ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2019b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by