matlab script in batch from unix command line?

조회 수: 1 (최근 30일)
Lester Ingber
Lester Ingber 2020년 5월 5일
댓글: Walter Roberson 2020년 5월 5일
I have a problem with Octave:
x = dlmread('fin');
y = transpose(x);
z = fft(y);
w = ifft(z);
dlmwrite('fout',w,' ');
fin is real, but fout is complex with all data have very small imaginary parts. This seems to be a known bug:
https://savannah.gnu.org/bugs/?45932
Matlab does not have this problem with this same code. However, while I can create a script to run fine as a batch job in Octave, I cannot do this in Matlab? For example, the first line in an Octave script is
#!/opt/octave/bin/octave -qf
but I have not been able to find the Matlab counterpart. For example,
#!/opt/matlab/2018a/bin/matlab
just puts me into Matlab instead of running the script. I have tried various flags that might be like Octave's "-qf" without success?
  댓글 수: 5
jessupj
jessupj 2020년 5월 5일
편집: jessupj 2020년 5월 5일
it's not graceful, but i've done this using commands in the shell, e.g. using the matlab '-r' in version up to 2018a.
i know that's not what you're asking for, but i didn't every try to call matlab functions as shell functions.
ARG1=$(some shell commands)
ARG2='/home/user/mfiles' # directory containing function.m
matlab -nodisplay -nosplash -r "addpath(${ARG2}); function(${ARG1}); quit"
the equivalent for octave was something like
octave --no-gui --eval "addpath(${ARG2}); function(${ARG1}); quit"
this way, i could put a switch between matlab and octave (depending on which machine i was using) and not have different *.m files for each.
Walter Roberson
Walter Roberson 2020년 5월 5일
When using -r I recommend adding a try/catch:
matlab -nodisplay -nosplash -r "try; addpath(${ARG2}); function(${ARG1}); catch ME;end; quit"

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Octave에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by