I want to start a matlab function from the unix command line. For now I use
matlab -nodisplay -r "functionname(argument1, argument2, argumentN);exit"
But for this the function I call needs to be in the folder where I am. Is there a way to call the function like
matlab -nodisplay -r "/path/to/functionname(argument1, argument2, argumentN);exit"
without manually adding it to the search path of matlab?

 採用された回答

Jan
Jan 2017 年 2 月 27 日

0 投票

Do you mean:
matlab -nodisplay -r "cd('/path/to'); functionname(argument1, argument2, argumentN);exit"

4 件のコメント

Simon Michel
Simon Michel 2017 年 2 月 27 日
Thank you very much for helping. This easily solved my problem.
Shep Bryan
Shep Bryan 2019 年 5 月 7 日
Does this change the directory that you are in permanantly or does it cd back after this command is called?
Jhe Mag
Jhe Mag 2022 年 1 月 16 日
編集済み: Jhe Mag 2022 年 1 月 16 日
Thank you Mr. Jan. Seems like windows prompt is slightly the same with unix haha.
Someone might be needing this: For windows command prompt, I used the command : "C:\Program Files\Polyspace\R2021a\bin\matlab.exe" -nosplash -nodesktop -r "cd('D:\matlab_project\scripts\'), testFnc('blah'), exit"
with my testFnc.m
function sample = testFnc(stri)
sample = stri
disp(sample)
end
Jon
Jon 2025 年 9 月 11 日
FWIW, this does seem to cd back to the original directory after MATLAB exits

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2025 年 9 月 12 日

0 投票

I'm not 100% sure this option was available in releases R2017a or R2017b, but I'm pretty sure it was. Use the -sd startup option to cause MATLAB to start in a certain directory.

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2017 年 2 月 27 日

編集済み:

2025 年 9 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by