www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/UseNodePropertiesInIsomorphismComparisonExample.m
%% Preserve Node Properties in Isomorphism Comparison % Use two different comparisons to determine if there is an isomorphism % relation between two graphs. One of the comparisons 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 = {'red' 'red' 'blue'}'; G2 = graph({'a' 'b' 'c'},{'b' 'c' 'a'}); G2.Nodes.Color = {'blue' 'blue' 'red'}'; %% % 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,{'d' 'e'},'NodeColor','r') subplot(1,2,2) p2 = plot(G2); highlight(p2,'c','NodeColor','r') %% % Determine if the graphs are isomorphic, ignoring the |Color| property. tf = isisomorphic(G1,G2) %% % Determine if the graphs are isomorphic and preserve the value of the % |Color| property in the comparison. In this case, there is no isomorphism % since the |Color| property of each graph contains different numbers of % |'red'| and |'blue'| values. tf = isisomorphic(G1,G2,'NodeVariables','Color')