-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpa_buildTwoPermutation.m
More file actions
54 lines (50 loc) · 1.17 KB
/
jpa_buildTwoPermutation.m
File metadata and controls
54 lines (50 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function perm = jpa_build2Permutation(vector)
% Function that returns all Permutations of input-vector consisting of
% two numbers.
% So Output for Input-Vector [1 2 3] would be [1 2] [1 3] [2 3]
%
% Syntax:
% perm = jpa_build2Permutation(vector)
%
% Inputs:
% vector - vector containing digits
%
% Outputs:
% perm - all Permutations of vector consisting of two numbers.
%
% Example:
% perm = jpa_build2Permutation([1 2 3])
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also:
% Author: Jan Albrecht
% Work address:
% email: jan-philipp.albrecht@charite.de, j.p.albrecht@fu-berlin.de
% Website:
% Sep 2015; Last revision: 29-Sep-2015
%------------- BEGIN CODE --------------
% Index
ind = 1;
% size
[a b] = size(vector);
% check if Permutation is usless
if b > 1
% run through all cols
for i=1:1:b-1
% run through all elements
for j =i+1:1:b
% build permutation
perm{ind} = [vector(i) vector(j)];
% increase index
ind = ind +1;
end
end
else
% set perm to vector
perm{1} = vector(1);
end
end
%------------- END CODE --------------