我遇到了同样的问题。这些警告不会改变代码的功能,但如果您尝试使用命令窗口来获得有用的输出,则会很痛苦。由于警告来自大量 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