필터 지우기
필터 지우기

run matlab function with arguments on linux terminal

조회 수: 88 (최근 30일)
Ayoub
Ayoub 2012년 5월 22일
댓글: Walter Roberson 2019년 6월 20일
Hello, do you have any idea how to run matlab functions from the linux shell specifying their arguments? what i tried was: { matlab -r myfunction(argument1,argument2) } but it doesn't work oO
  댓글 수: 2
Yekaterina Gilbo
Yekaterina Gilbo 2017년 7월 14일
Hi Ayoub, what is the purpose of the "-r" and also how do you know what to even type on the terminal (what should I look up for this?) Thanks!
Walter Roberson
Walter Roberson 2017년 7월 14일
"-r" followed by something indicates that MATLAB should take what follows as a command to run.

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

채택된 답변

Walter Roberson
Walter Roberson 2012년 5월 22일
matlab -r 'myfunction(argument1,argument2)';
Or safer:
matlab -r 'try myfunction(argument1,argument2); catch; end; quit'

추가 답변 (4개)

Thomas
Thomas 2012년 5월 22일
Adding to Walter's answers above..
you could also try
matlab -r -nodisplay -nojvm 'myfunction(argument1,argument2)';
-no display removes the Xdisplay and -nojvm starts matlab without hte Java virtual machine.
you could also try
matlab -r -nodesktop -nojvm 'myfunction(argument1,argument2)';
or use the abovewith the try-catch loop as suggested by Walter..

USMAN
USMAN 2014년 7월 15일
I would rearrange the sequence of input arguments as follows:
matlab -nodisplay -nojvm -r 'FunctionName Arg1 Arg2; exit;'
exit will also exit Matlab and bring control back to shell
  댓글 수: 1
Patrik Ek
Patrik Ek 2015년 1월 2일
Which is the only way to use the -r argument. Good add!

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


Ayoub
Ayoub 2012년 5월 29일
thankyou guys :)

Martina Audagnotto
Martina Audagnotto 2018년 5월 21일
편집: Walter Roberson 2018년 5월 22일
Hi,
I have a similar question regarding running matlab with arguments on linux terminal. I want to run my matlab code on GPU and if I set the number of GPU manually the code run, while if i give the number of GPU as a variable of my function I get the following error:
Not enough input arguments.
This is how I run the function:
matlab -nodesktop -r "nodes=2; averaging_filament='single_filament_averaging_reikaparam_is40'; folder='polarity_TRIAL'; run streamline_tomo_GPU.m" ;
and inside the code:
GPU=[nodes];
No idea why is it not running :(
  댓글 수: 3
Lucademicus
Lucademicus 2019년 6월 20일
According to the matlablinux documentation, you should not use the option
-r
but instead use the option
-batch
I've tested this on MATLAB R2018b.
The command
matlab -nodisplay -nojvm -r 'somefunction(someargument); anotherfunction(anotherargument);'
did not run anotherfunction(). It did when I changed -r to -batch!
Walter Roberson
Walter Roberson 2019년 6월 20일
-batch is a new option as of R2019a. -r still works.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by