运行matlab命令行并自动运行unix服务器bjobs



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

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命令行。

您可以将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文件加载到结构中以处理加载的变量可以在这里找到更多详细信息。

最新更新