簡體   English   中英

在Shell腳本中運行MATLAB函數(Mac)

[英]Running MATLAB function in shell script (Mac)

有沒有一種方法可以在外殼程序腳本中使用輸入來運行MATLAB函數,然后打印/存儲輸出? 我編寫了一個示例函數和shell腳本,該腳本運行時沒有錯誤,但沒有為我提供任何結果。

我希望從shell腳本中獲得的是使用輸入nm運行函數sample.m (位於名為“ cluster”的文件夾中),然后將結果分配給工作區。 我的最終目標是向集群提交更復雜的代碼,但我想先了解一下shell腳本如何更好地工作。

我想用產生它們的nm值記錄每次迭代的輸出。 是否有捷徑可尋?

這是我的示例MATLAB函數:

 function x = sample(n,m)
    x = 10*rand(n,m);
 end

這是我的shell腳本:

#!/bin/bash 
for m in 1 2 3 4
do 
for n in 1 2 3 4
do
     cmd=$ /Applications/MATLAB_R2016b.app/bin/matlab -nodesktop -nojvm -nodisplay -nosplash -r "try; sample $n $m; end; quit;" 
     echo $cmd
done
done

這是終端的結果:

ssss:cluster cbruno$ bash sample.sh

                            < M A T L A B (R) >
                  Copyright 1984-2016 The MathWorks, Inc.
                   R2016b (9.1.0.441655) 64-bit (maci64)
                             September 7, 2016


For online documentation, see http://www.mathworks.com/support
For product information, visit www.mathworks.com.


ssss:cluster cbruno$ 

請按以下方式使用“ -logfile ”選項

#!/bin/bash 
for m in 1 2 3 4
do 
for n in 1 2 3 4
do
    cmd=$ /Applications/MATLAB_R2016b.app/bin/matlab -nodesktop -nojvm -nodisplay -nosplash -logfile log-$m-$n.txt -r "try; sample $n $m; end; quit;" 
    echo $cmd
done
done

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM