循环调用matlab中的外部程序

calling an external program in matlab in a loop

我已经在 Ubuntu 中安装了 Matlab 2014。我的问题: 我在 Matlab 中为另一个程序 Quantum Espresso 构建了几个输入文件。现在我应该使用 matlab 命令行将这些文件传递给 Quantum Espresso。现在我知道我可以使用 Linux 终端来做到这一点,但我解决问题的方式已经到了我唯一的选择是 'calling Quantum Espresso from matlab' 的地步。一通电话其实很简单:

!  installation/folder/espresso-5.3.0/bin/pw.x <  inputfile > outputfile

问题是我有几个输入文件命名为 1name.in 1name.in ...。所以这个重复的调用应该在一个循环中完成。但是怎么办?

我试过: shell 用于循环文件的脚本。我添加了额外的'!'到脚本的每一行,但它不起作用。 我也试过写一个这样的循环:

for i = 1:N

prefix = int2str(i);
fuloutname = [prefix 'name' '.' 'out'];
fulinname  = [prefix 'name' '.' 'in'];
!  adress/espresso-5.3.0/bin/pw.x <  fulinname > fuloutname ;

end

其中 'N' 个我的输入文件。显然 运行 这意味着您正在传递一个文件 nemaed 'fulinname' 而不是 1name.in 并且将导致一个名为 'fuloutname'

的输出文件

我也尝试这样做,因为您通常会循环加载各种文件,但它也没有用

请帮帮我

您应该使用 unix 函数:

for i = 1:N

prefix = int2str(i);
fuloutname = [prefix 'name' '.' 'out'];
fulinname  = [prefix 'name' '.' 'in'];
mycommand  = ['adress/espresso-5.3.0/bin/pw.x <  ',fulinname,' > ',fuloutname];
unix(mycommand);
%system(mycommand); %will give you the same, result and this function is cross-platform

end