Home > matgraph > @graph > resize.m

resize

PURPOSE ^

resize(g,n) --- change the number of vertices in g to n

SYNOPSIS ^

function resize(g, n)

DESCRIPTION ^

 resize(g,n) --- change the number of vertices in g to n
 note: if n is less than nv(g), vertices will be lost
 if the graph has an embedding, all new vertices are sited at the origin.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function resize(g, n)
0002 % resize(g,n) --- change the number of vertices in g to n
0003 % note: if n is less than nv(g), vertices will be lost
0004 % if the graph has an embedding, all new vertices are sited at the origin.
0005 
0006 
0007 old_n = nv(g);
0008 
0009 if (n == old_n)   % no change
0010     return
0011 end
0012 
0013 global GRAPH_MAGIC
0014 
0015 if (n < old_n)    % shrink
0016     GRAPH_MAGIC.graphs{g.idx}.array = ...
0017         GRAPH_MAGIC.graphs{g.idx}.array(1:n,1:n);
0018     make_logical(g);
0019     if hasxy(g)
0020         GRAPH_MAGIC.graphs{g.idx}.xy = ...
0021             GRAPH_MAGIC.graphs{g.idx}.xy(1:n,:);
0022     end
0023     if is_labeled(g)
0024         GRAPH_MAGIC.graphs{g.idx}.labels = ...
0025             GRAPH_MAGIC.graphs{g.idx}.labels(1:n);
0026     end
0027     return
0028 end
0029 
0030 % we need to add extra zeros to g's adjacency matrix. we decide what to do
0031 % based on g's storage class.
0032 
0033 if (isfull(g))
0034     A = zeros(old_n, n-old_n);
0035     B = zeros(n-old_n, n-old_n);
0036 else
0037     A = sparse([],[],[],old_n,n-old_n);
0038     B = sparse([],[],[],n-old_n,n-old_n);
0039 end
0040 
0041 if hasxy(g)
0042     morexy = zeros(n-old_n,2);
0043     GRAPH_MAGIC.graphs{g.idx}.xy = ...
0044         [GRAPH_MAGIC.graphs{g.idx}.xy; morexy];
0045 end
0046  
0047 if is_labeled(g)
0048     newlabels = cell(n,1);
0049     for k=1:old_n
0050         newlabels{k} = GRAPH_MAGIC.graphs{g.idx}.labels{k};
0051     end
0052     for k=(old_n+1):n
0053         newlabels{k} = int2str(k);
0054     end
0055     GRAPH_MAGIC.graphs{g.idx}.labels = newlabels;
0056 end
0057 
0058 GRAPH_MAGIC.graphs{g.idx}.array = ...    
0059     [GRAPH_MAGIC.graphs{g.idx}.array, A; A', B];
0060 make_logical(g);

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003