运行matlab命令行并自动运行unix server bjob​​s

时间:2012-12-04 18:29:37

标签: bash matlab lsf

我正在以这种方式运行一大块matlab代码,名为 fit.m

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

alldata.mat有几个感兴趣的数据,即

rxw1
rbg2
rfd1
wop3, 
ltgbd,
etc.

我可以从命令行为给定的感兴趣的数据运行这样的脚本(在我的例子中为count = 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命令行。

1 个答案:

答案 0 :(得分: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...

修改 类似的解决方案将mat文件加载到struct中以处理加载的变量 可以在here找到更多详细信息。