简体   繁体   English

如何从八度列表中安装很多软件包?

[英]How to install a lot of packages from a list in octave?

I would want to install a few packages in an automated way and i was trying do this using a simple for loop. 我想以自动化的方式安装一些软件包,而我尝试使用简单的for循环进行此操作。 As shown below. 如下所示。

   pkgs = '../pkgs';
   names = dir(fullfile(pkgs, '*.tar.gz')); 
   n = numel(nomes);
   for i = 1:n
        pkg install names(n).name
   end

This is first attempt that returns to me this 8 times 这是我第一次尝试这8次

warning: file names(n).name does not exist

And i'm looking for a way to get the ans value of names.name. 而且我正在寻找一种获取names.name的ans值的方法。

Instead of all that code, you can use 'glob()' to get the list of tarballs, and then a single pkg() call to install all of them. 除了使用所有代码之外,您还可以使用'glob()'获取tarball列表,然后使用一个pkg()调用来安装所有文件。 Like so: 像这样:

fpaths = glob ("pkgs/*.tar.gz");
pkg ("install", fpaths{:});

MATLAB and Octave both allow the easy syntax of MATLAB和Octave都允许使用以下简单语法

functionname arg1 arg2 ...

by translating it to the proper function call 通过将其翻译为适当的函数调用

functionname('arg1','arg2',...);

This implies that in order to pass the value of variables as arguments (rather than the variable names themselves), you must use the functional form: 这意味着为了将变量的作为参数传递(而不是变量名称本身),必须使用函数形式:

pkgs = '../pkgs';
names = dir(fullfile(pkgs, '*.tar.gz')); 
n = numel(names);                    %// fixed your typo here
for k = 1:n
     pkg('install',names(k).name)    %// changed here, also n -> i -> k
end

Note that you had two typos: names was written as nomes in line 3 (translation issue, probably), and more importantly, you were using n rather than i in the loop. 请注意,您有两种错别字: names在第3行中以nomes编写(可能是翻译问题),更重要的是,您在循环中使用n而不是i As a matter of fact, don't use i as a variable in Octave: that stands for the imaginary unit, and can lead to subtle errors if you're uncautious. 实际上,不要在Octave中将i用作变量:代表虚构单位,如果您不谨慎,则可能导致细微的错误。 I changed to k in the above code. 我在上面的代码中更改为k

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM