www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ComputeIsomorphismAndPreserveNodePropertiesExample.m

    %% Compute Isomorphism and Preserve Node Properties
% Compute two different isomorphism relations between two graphs. One of
% the relations preserves a node property, while the other ignores it.
%
% Create two similar graphs. Add a node property |Color| to each of the
% graphs.
G1 = graph({'d' 'e' 'f'},{'e' 'f' 'd'});
G1.Nodes.Color = {'blue' 'red' 'red'}';

G2 = graph({'a' 'b' 'c'},{'b' 'c' 'a'});
G2.Nodes.Color = {'red' 'red' 'blue'}';

%%
% Plot the graphs side-by-side in the same figure. Color the nodes red that
% have |Color = 'red'|.
subplot(1,2,1)
p1 = plot(G1);
highlight(p1,{'e' 'f'},'NodeColor','r')

subplot(1,2,2)
p2 = plot(G2);
highlight(p2,{'a' 'b'},'NodeColor','r')

%%
% Compute the isomorphism between the graphs, ignoring the |Color|
% property.
p = isomorphism(G1,G2)

%%
% Compute the isomorphism again, but this time preserve the value of the
% |Color| property in the comparison. |isomorphism| returns a different
% permutation that preserves the |Color| property.
p = isomorphism(G1,G2,'NodeVariables','Color')

%%
% View the nodes in |G1| and |G2| that the isomorphism matches together.
[G1.Nodes.Name, G2.Nodes.Name(p)]