Code covered by the BSD License

# LVPermute

### Ahmed A. Selman (view profile)

A simple (Line Vector Permutation) function.

[C,D,j]=lvpermute(varargin)
```function [C,D,j]=lvpermute(varargin)
% LVPERMUTE (Linear Vector Permutation) function used to find possible
% permutation of a linear, one-dimensional vector.
%
% Usage:
% A=lvpermute(n)
% Generates a (1 by n) matrix, and outputs its possible permutations in
% the matrix A.
%
% [A,B]=lvpermute(n)
% Generates a matrix B=(1 by n), and outputs its possible permutations in
% the matrix A.
%
% [A,B,k]=lvpermute(n)
% Generates a matrix B=(1 by n), and outputs its possible permutations in
% the matrix A, with all possible permutations made in k.
%

% lvpermute.m Function, ver 1.00
% by Ahmed A. Selman, 15 April 2013
% User notice: Please note that this is a very simple permutation function,
% with possible future modifications.
n=varargin{1};
if nargin > 1
error('myApp:argChk',...
'Too many input arguments. Maximum input arguments is 1.');
end
if ( (ischar(n)) || (fix(n) ~= n) || (n <= 0) || (~isreal(n)) )
error('MATLAB:factorial:NNegativeInt', ...
'n must be positive integer only.');
end
A=1:n;
D=A;
B=zeros(1,numel(A));
C=zeros(numel(A),factorial(numel(A)));
for j=1:factorial(numel(A));
for i=1:numel(A)
if i==numel(A)
B(i)=A(1);
break
end
B(i)=A(i+1);
end
C(:,j)=B;
A=B;
end
C=C';```