graphnodeadd.m

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

M
39
字号
function Graph = GraphNodeAdd(Graph,NodeID,NodeName)
% Adds the specified Node(s) to the dictionary, If node with that ID already exists, it's name is changed.
%
%
% Receives:
%   Graph       -   Graph Struct                 -   the graph loaded with GraphLoad
%   NodeID      -   integer or vector of integers  -  the ID(s) of the node(s) to be added.
%   NodeName    -   string or cellstr           -   (list of) name(s) of the node. Must have the same nummber of elements as the NodeID vector
%
% Returns:
%   Graph       -   Graph Struct                -   the graph with with the node added to the dictionary.
%
% Remarks:
%   mexGraphSqueeze is not called - the node IDs are no changed. 
%
% See Also:
%       GraphLoad, GraphLinkFind, GraphLinkRemove, mexGraphSqueeze, GraphLinkAdd
%
% Created:
%   Lev Muchnik    21/02/2005, Tel.: 972-054-4326496, Train Amsterdam->Cologne

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

if ~isfield(Graph,'Index')
    EmptyGraph = ObjectCreateGraph();
    Graph.Index = EmptyGraph.Index;
end
if numel(NodeID) ~= 1
    NodeID = reshape(NodeID,[numel(NodeID) 1]);
    NodeName = reshape(NodeName,[numel(NodeName) 1]);
else
    NodeName = cellstr(NodeName);
end
[c,ia,ib] = intersect(Graph.Index.Values,NodeID);
Graph.Index.Names{ia} = NodeName{ib};
ic = setdiff([1:numel(NodeID)],ib);
Graph.Index.Values = [ Graph.Index.Values; NodeID(ic)];
Graph.Index.Names = [ Graph.Index.Names; NodeName(ic)];

⌨️ 快捷键说明

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