0001 function p = permutation(n)
0002
0003
0004
0005
0006
0007 if nargin==0
0008 n = 1;
0009 end
0010
0011 bad = 'Input invalid: must be a permutation of 1:n or a single integer';
0012 [r,c] = size(n);
0013
0014 if (r>1) && (c>1)
0015 error(bad);
0016 end
0017
0018 if (r==1) && (c==1)
0019 x = 1:n;
0020 else
0021 x = n;
0022 end
0023
0024
0025 x = x(:)';
0026 n = length(x);
0027
0028
0029 y = sort(x);
0030 if any(y ~= 1:n)
0031 error(bad);
0032 end
0033
0034 p.array = x;
0035 p = class(p,'permutation');