⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generatestats.m

📁 分析了ofdm系统的过程
💻 M
📖 第 1 页 / 共 2 页
字号:

%==========================================================================
function strc = getcallinfo(filename,option)
%GETCALLINFO  Returns called functions and their initial calling lines
%   STRUCT = GETCALLINFO(FILENAME,OPTION)
%   The output structure STRUCT takes the form
%      type:       [ script | function | subfunction ]
%      name:       name of the script, function, or subfunction
%      firstline:  first line of the script, function, or subfunction
%      calls:      calls made by the script, function, or subfunction
%      calllines:  lines from which the above calls were made
%
%   OPTION = [ 'file' | 'subfuns' | 'funlist' ]
%   By default OPTION is set to 'subfuns'
%
%   OPTION = 'file' returns one structure for the entire file, regardless
%   of whether it is a script, a function with no subfunctions, or a
%   function with subfunctions. For a file with subfunctions, the calls
%   for the file includes all external calls made by subfunctions.
%
%   OPTION = 'subfuns' returns an array of structures. The first is for the
%   for the main function followed by all of the subfunctions. This option
%   returns the same result as 'file' for scripts and one-function files.
%
%   OPTION = 'funlist' returns an array of structures similar to the
%   'subfuns' option, but calls and calllines information is not
%   returned, only the list of subfunctions and their first lines.

%   Copyright 1984-2004 The MathWorks, Inc.
%   Ned Gulley

if nargin < 2
    option = 'subfuns';
end

mlintMsg = mlintmex('-calls',filename);

mainFcnHit =  regexp(mlintMsg,'M0 (\d+) \d+ (\w+)','tokens','once');
subFcnHits = regexp(mlintMsg,'S0 (\d+) \d+ (\w+)','tokens');
filenameHit = regexp(filename,'(\w+)\.[mM]?$','tokens','once');
if isempty(filenameHit)
    error('Illegal filename "%s"',filename)
end
shortfilename = filenameHit{1};

strc = [];

% TODO: watch out for nested functions
if isempty(mainFcnHit)
    % File is a script
    strc.type = 'script';
    strc.name = shortfilename;
    hits = regexp(mlintMsg,'U0 (\d+) \d+ (\w+)','tokens');
    strc.firstline = 1;
    strc.calls = cell(length(hits),1);
    strc.calllines = zeros(length(hits),1);
    for n = 1:length(hits)
        strc.calllines(n) = eval(hits{n}{1});
        strc.calls{n} = hits{n}{2};
    end

else
    % File is a function
    strc(1).type = 'function';
    strc(1).name = shortfilename;
    strc(1).firstline = 1;
    callHits = regexp(mlintMsg,'U1 (\d+) \d+ (\w+)','tokens');

    if strcmp(option,'funlist')

        for n = 1:length(subFcnHits)
            strc(n+1).type = 'subfunction';
            strc(n+1).name = subFcnHits{n}{2};
            strc(n+1).firstline = eval(subFcnHits{n}{1});
        end

    elseif strcmp(option,'file')

        strc(1).calls = {};
        strc(1).calllines = [];
        localFuns = {};
        % Get list of all local functions for de-duping
        for n = 1:length(subFcnHits)
            localFuns{end+1} = subFcnHits{n}{2};
        end
        localFunStr = sprintf('%s ',localFuns{:});

        for n = 1:length(callHits)
            callLine = eval(callHits{n}{1});
            call = callHits{n}{2};
            % Only put the call on the list if it's not a local function
            if isempty(strfind(localFunStr,call))
                strc.calllines(end+1) = callLine;
                strc.calls{end+1} = call;
            end
        end

    else

        strc(1).calls = {};
        strc(1).calllines = [];
        for n = 1:length(subFcnHits)
            strc(n+1).type = 'subfunction';
            strc(n+1).name = subFcnHits{n}{2};
            strc(n+1).firstline = eval(subFcnHits{n}{1});
        end

        % Get list of all first lines for figuring which function to associate
        % the call with
        firstLines = [strc.firstline];

        for n = 1:length(callHits)
            callLine = eval(callHits{n}{1});
            call = callHits{n}{2};
            lineCompare = find(callLine > firstLines);
            strc(lineCompare(end)).calllines(end+1) = callLine;
            strc(lineCompare(end)).calls{end+1} = call;
        end

    end
end

%==========================================================================
function msgs = getMlintMessages(file)

% Get all the M-lint messages for this file.
msgs = mlint(file);

% Strip out messages taht can't be avoided.
ignore = strmatch('The value assigned here to variable ',{msgs.message});
msgs(ignore) = [];
ignore = ~cellfun('isempty',regexp({msgs.message},'Input variable ''.*?'' appears never to be used\.'));
msgs(ignore) = [];
ignore = ~cellfun('isempty',regexp({msgs.message},'Function ''.*?'' appears never to be used\.'));
msgs(ignore) = [];

% Strip out this one, as it makes examples look bad.
ignore = strmatch('Terminate statement with semicolon to suppress output.',{msgs.message});
msgs(ignore) = [];

%==========================================================================
function [clash,clashname] = getClash(file)

[path,filename,ext] = fileparts(file);
fname = [filename ext];

if any(path == '@')
    % Ignore methods.
    clashname = '';

elseif strcmpi(fname,'Contents.m') || strcmpi(fname,'Readme.m')
    % These are OK.
    clashname = '';

else
    % Locate.
    clashname = which(fname);

    % Exclude files in this directory.
    helperdir = fileparts(which(mfilename));
    if strmatch(helperdir,clashname)
        clashname = '';
    end

    % Remove MATLABROOT and normalize filesep.
    clashname = strrep(strrep(clashname,[matlabroot filesep],''),filesep,'/');

    % Exclude methods.
    if any(clashname == '@')
        clashname = '';
    end
    
end

% Define the first output.
clash = ~isempty(clashname);


%==========================================================================
function details = getCloneInfo(fileList,dirname)
%getCloneInfo Returns the cloned code info.
%   getCloneInfo finds cloned code for fileList relative to dirname.

% Create the empty return structure.
details = struct('file1',{},'start1',{},'end1',{},'file2',{},'start2',{},'end2',{});

if ~ispc && ~strcmp(computer,'GLNX86')
    % The executible only runs on some platforms.
    return
end

% Create a temporary file for mdf.exe to act on.
tempfile = tempname;
fid = fopen(tempfile, 'w+');
for i = 1:size(fileList,2)
    fprintf(fid,'%s\n',fileList{i});
end
fclose(fid);

% Call the external executable.
thisDir = fileparts(mfilename('fullpath'));
mdfExe = fullfile(thisDir,'mdf');
[status,out] = system(['"' mdfExe '" "' tempfile '"']);
if status ~= 0
    error(out)
end
delete(tempfile)

% Parse the output.
pattern = '(\S+\.m):\((\d+)-(\d+))\s+MATCHES\s+(\S+\.m):\((\d+)-(\d+))';
info = regexp(out,pattern,'tokens');

% Translate the matches into a structure.
for i = 1:size(info,2)
    details(end+1).file1 = removeBase(info{i}{1},dirname);
    details(end).start1 = str2double(info{i}{2});
    details(end).end1 = str2double(info{i}{3});
    details(end).file2 = removeBase(info{i}{4},dirname);
    details(end).start2 = str2double(info{i}{5});
    details(end).end2 = str2double(info{i}{6});
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -