0

我正在并行运行具有不同参数的 CVX。串行运行时,我没有收到任何警告,但并行运行(使用 parfor),我得到以下信息:

 In cvx/bcompress (line 2)
  In cvxprob/newcnstr (line 233)
  In cvxprob/newcnstr (line 72)
  In == (line 3)
  In cvx/abs (line 68)
  In cvx/norm (line 56)
  In remove_l (line 27)
  In parallel_function>make_general_channel/channel_general (line 914)
  In remoteParallelFunction (line 38)
Warning: NARGCHK will be removed in a future release. Use NARGINCHK or NARGOUTCHK instead.

我以前没有见过这个,我不知道如何解决它。任何帮助表示赞赏。

4

2 回答 2

1

警告没什么好担心的……至少是立即的。请记住,这是一个警告,因此您的代码仍应运行。它只是告诉您该功能nargchk已被弃用,您应该使用较新的版本:narginchk而是nargoutchk。您可以在此处的 MathWorks 官方文档中看到此警告:http nargchk: //www.mathworks.com/help/matlab/ref/nargchk.html。我的猜测是 CVX 的最后一个版本是在 MATLAB 决定做出这个决定之前开发的。

因此,您所要做的就是进入第bcompress2 行的文件并更改nargchknarginchk. 具体来说,当你下载时cvx,打开包含代码的文件夹,然后去/lib/@cvx/bcompress.m。将第 2 行的行更改error(nargchk(1, 3, nargin));error(narginchk(1, 3));.

如果您不打算升级您的 MATLAB 版本并且想要坚持使用当前版本,那么您可以简单地忽略该警告。narginchk有关详细信息,请参阅 MathWorks 帮助文件:http: //www.mathworks.com/help/matlab/ref/narginchk.html

于 2016-09-13T14:52:52.137 回答
0

我遇到了同样的问题。这些警告不会改变代码的功能,但如果您尝试使用命令窗口来获得有用的输出,则会很痛苦。由于警告来自大量 CVX 文件,我编写了一个脚本来修复它们。

要使用 nargchk 修复所有 CVX 文件,请将以下代码复制到名为“update_nargchk.m”的文件中,然后在不带参数的 cvx 根文件夹中运行它,或者使用指向 cvx 根文件夹的字符串参数从其他地方运行它。

function update_nargchk(directory)
%UPDATE_NARGCHK Updates files using the depricated nargchk
%   All files in the specified directory (or current directory if
%   unspecified) are searched. If an instance of nargchk is found being
%   used (with nargin) it is updated to use narginchk with the same values.

if ~exist('directory','var')
    directory = '.';
end

recurse(directory);

end

function recurse( folder )

d = dir(folder);
for elem = 1:length(d)
    if ~strcmp(d(elem).name,'.') && ~strcmp(d(elem).name,'..')
        if d(elem).isdir
            recurse([folder '/' d(elem).name]);
        else
            if strcmp(d(elem).name(end-1:end),'.m') 
                updateFile([folder '/' d(elem).name]);
            end
        end
    end
end

end

function updateFile(filename)

% read file contents into workspace
fid = fopen(filename);
C=textscan(fid,'%s','delimiter','\n','whitespace','');
C = C{1,1};
fclose(fid);

% check for instances of nargchk
instanceFound = false;
for k=1:numel(C)
    textline = C{k,1};
    if ~isempty(regexp(textline,'^[^%]*nargchk','ONCE')) && ...
            ~isempty(regexp(textline,'^[^%]*nargin','ONCE'))
        instanceFound = true;
        nums = regexp(textline,'(\d+|-?Inf)','tokens');
        nums = [str2double(nums{1}) str2double(nums{2})];
        C(k) = {['narginchk(' num2str(nums(1)) ',' num2str(nums(2)) '); % Modified from: ' textline]};
    end
end

if instanceFound
    % print new file
    fid = fopen(filename,'w'); % Open the file
    for k=1:numel(C)
        fprintf(fid,'%s\r\n',C{k,1});
    end
    fclose(fid);
    disp([filename ' updated'])
end

end
于 2016-09-15T19:38:04.820 回答