graphcountnodedegree.m

来自「复杂网络的一些节点面对攻击的代码」· M 代码 · 共 27 行

M
27
字号
function Degree = GraphCountNodeDegree(Graph,NodeID)
% Computes and returns the degree (number of incoming & outgoing links) for the specified node in graph.
% Unlike 'GraphCountNodesDegree' operates with single node only, but much more effective.
%
% Receives:
%   Graph       -   Graph Struct          -   the graph loaded with GraphLoad
%   Node          -   single id                  -   The ID of the node to be returned. The ID may not  be in the graph - (0,0) will be returned.
%
% Returns:
%   Degree      -   2x1 vector of integer   -   Degree(1) - incoming node degree, Degree(2) - outgoing.
%
% Remarks:
%       For efficiency, the function does not validate that Graph  indeed represents Graph
%
% See Also:
%       GraphLoad, GraphCountNodesDegree
%
% Created:
%   Lev Muchnik    03/08/2005, Tel.: 972-054-4326496
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

error(nargchk(2,2,nargin));
error(nargoutchk(0,1,nargout));

Degree = [0 0];
Degree(1) = nnz(Graph.Data(:,2)==NodeID);
Degree(2) = nnz(Graph.Data(:,1)==NodeID);

⌨️ 快捷键说明

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