Code covered by the BSD License  

Highlights from
MATLAB Contest - Sailing Home

image thumbnail

MATLAB Contest - Sailing Home

by

 

09 Nov 2010 (Updated )

All the files needed to develop and score an entry for the MATLABĀ® Programming Contest.

getcomplexity(filename)
function maxComplexity = getcomplexity(filename)
%GETCOMPLEXITY  Calculate the maximum complexity in an M-file.
%   maxComplexity = getcomplexity(filename)
%
%   "Complexity" refers to the McCabe complexity as returned by "mlint -cyc"
%   When there are multiple functions in a file, the maximum value is
%   returned.

% Copyright 2010 The MathWorks, Inc.

msg = mlint('-cyc','-string',filename);
tk = regexp(msg,'McCabe complexity of [^\s]+ is (\d+)','tokens');
complexity = zeros(size(tk));
for j = 1:length(tk)
    complexity(j) = eval(tk{j}{1});
end
maxComplexity = max(complexity);

Contact us