2012-12-04 45 views
3

我跑叫fit.m這樣的MATLAB代碼塊,運行MATLAB命令行和自動化運行UNIX服務器bjobs

clear all; 
load('/pathtomatfile/alldata.mat') 
count = rxw1; 
count = double(count); 
x_cov = ltgbd; 

alldata.mat有幾個感興趣的數據,即,

rxw1 
rbg2 
rfd1 
wop3, 
ltgbd, 
etc. 

我可以從對於感興趣的給定的數據在命令行運行這樣腳本(在我的示例計數= rxw1)

matlab -nodisplay -nojvm -nosplash -r ${pathtoscript}fit -logfile lfile.txt 

但是,我需要自動運行,以便我可以告訴matlab使count = mat文件中的任何其他數據集。即,我想在平行的腳本不同的數據集,但我需要這樣的:

matlab -nodisplay -nojvm -nosplash -r ${pathtoscript}fit -logfile lfile.txt DATAOFINTERESTHERE (i.e., rxw1 count will equal rxw1, etc.) 

是否有可能做我的建議?當我調用腳本時,如何通過將數據集的名稱作爲輸入參數來自動運行腳本以運行我選擇的任何數據集?

一旦我有計劃實際上是通過LSF提交作業,但在心中給感興趣的數據的名稱作爲輸入,像這樣運行它們全部並行:

bsub -q week -R'rusage[mem=8000]' \ 
"matlab -nodisplay -nojvm -nosplash -r ${pathtoscript}fit -logfile lfile.txt DATAOFINTEREST" 

很抱歉,如果它太Q的基礎,但我不熟悉運行matlab命令行。

回答

3

你可以用fit來代替腳本。 fit功能可以有一個單一的輸入變量指向正確的數據文件。 然後你可以運行

matlab -nodisplay -nojvm -nosplash -r "cd ${pathtoscript}; fit('${dataofinterest}');exit;" 

編輯:添加了這個詳細的fit樂趣。

fit功能應該是這個樣子

function fit(variableName) 
% 
% run fit for a specific variable from the mat file 
% variableName is a string, e.g. variableName = 'rgb1'; 
% 

ld = load('/pathtomatfile/alldata.mat'); 
count = ld.(variableName); % access variables in mat file as struct fields 
count = double(count); 
% and I believe you can take it from here... 

編輯: 類似的解決方案加載墊文件轉換成一個結構來處理加載變量 可以發現here有一些更多的細節。

+0

非常感謝。它不能解決我的問題,因爲我沒有很多mat文件。 mat文件只有一個文件,裏面有我感興趣的所有數據(變量),這是我面對的主要問題。我可以嘗試分割這樣的文件,但正在尋找更方便的東西。 – Dnaiel

+0

@Dnaiel我編輯了我的答案,我相信現在可以解決你的問題。 – Shai

+0

你是我的朋友! thx太多了! – Dnaiel