graphremoveduplicatelinks.m

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

M
31
字号
function Graph = GraphRemoveDuplicateLinks(Graph)
% Removes duplicate links from the graph
%
% Receives:
%   Graph       -   Graph Struct    -   the graph loaded with GraphLoad
%
% Returns:
%   Graph       -   Graph Struct    -   the graph loaded with GraphLoad without duplicate links
%
% See Also:
%       GraphLoad, GraphCountNumberOfLinks
%
% Created:
%   Lev Muchnik    22/02/2005, Tel.: 972-054-4326496
%
% Major Changes:
%   Lev Muchnik    20/10/2005, Tel.: 972-054-4326496
%   A multiplication factor is now : (NumberOfNodes+1) and not just NumberOfNodes. This could
%   cause problem in the extreme case when the last node was connected to the first node.

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

% NumberOfNodes  = GraphCountNumberOfNodes(Graph);
if size(Graph.Data,1)>0
    NumberOfNodes  = max(max(Graph.Data(:,1:2)));
    Indeces = Graph.Data(:,1)*(NumberOfNodes+1) + Graph.Data(:,2);
    [Indeces m n]=unique(Indeces);
    IndecesToKill = setdiff([1:GraphCountNumberOfLinks(Graph)],m);
    Graph.Data(IndecesToKill,:)=[];
end

⌨️ 快捷键说明

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