Code covered by the BSD License  

Highlights from
Matgraph

from Matgraph by Ed Scheinerman
Toolbox for working with simple, undirected graphs

Description of display
Home > matgraph > @permutation > display.m

display

PURPOSE ^

display(p) --- display a permutation in disjoint cycle form.

SYNOPSIS ^

function st = display(p)

DESCRIPTION ^

 display(p) --- display a permutation in disjoint cycle form.

CROSS-REFERENCE INFORMATION ^

This function calls:
  • cycles cycles(p) returns a cell array containing the cycle structure of p
  • length length(p) gives the size of the permutation
This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function st = display(p)
0002 % display(p) --- display a permutation in disjoint cycle form.
0003 
0004 
0005 % special case if the permutation is empty
0006 if (length(p)==0)
0007     disp('()')
0008     return
0009 end
0010 
0011 c = cycles(p);
0012 outstr = '';
0013 
0014 for k=1:length(c)
0015     outstr = [outstr,list_to_cycle(c{k})];
0016 end
0017 
0018 
0019 if nargout > 0
0020     st = outstr;
0021 else
0022     disp(outstr)
0023 end
0024 
0025 
0026 function str = list_to_cycle(list)
0027 if length(list) == 0
0028     str = '()'
0029     return
0030 end
0031 
0032 str = '(';
0033 for k=1:length(list)
0034     str = [str,int2str(list(k))];
0035     if k < length(list)
0036         str = [str,','];
0037     else
0038         str = [str,')'];
0039     end
0040 end

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

Contact us at files@mathworks.com