help:how to generate different combinations of a sequence
help:how to generate different combinations of a sequence
(OP)
suppose i have an intial sequence [1 2 3]
i want to genereate all different possible combinations of sequence like
1 2 3
1 3 2
2 3 1
2 1 3
3 1 2
3 2 1
i want to generate this inside an inner loop,and everytime i come inside this innerloop i want to take a different combination
suppose when i first come inside the inner loop and select a sequence , next time when i come into inner loop again i dont want to select already selected sequence ,so everytime i want to select a different sequence.
can anyone help me with this.
i want to genereate all different possible combinations of sequence like
1 2 3
1 3 2
2 3 1
2 1 3
3 1 2
3 2 1
i want to generate this inside an inner loop,and everytime i come inside this innerloop i want to take a different combination
suppose when i first come inside the inner loop and select a sequence , next time when i come into inner loop again i dont want to select already selected sequence ,so everytime i want to select a different sequence.
can anyone help me with this.





RE: help:how to generate different combinations of a sequence
EG
1 2 3
=5^1 + 3^2 +2^3
=5+9+8
=22
each code generated is unique.
Then you can sort and check whether your next suggestion has already ben generated.
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: help:how to generate different combinations of a sequence
% Example set of values to permute
x=[5 6 7];
% Create all permutations
n=length(x);
idx=dec2base(0:n^n-1,n)+1-'0';
allperms=x(idx);
% Create a random indexing vector
m=size(idx,1);
index=randperm(m);
% Loop through indexing vector
for i=1:m
val=allperms(index(i),:);
disp(val)
end
RE: help:how to generate different combinations of a sequence
% Example set of values to permute
x=[5 6 7];
% Create all permutations
allperms=perms(x);
% Create a random indexing vector
m=size(allperms,1);
index=randperm(m);
% Loop through indexing vector
for i=1:m
val=allperms(index(i),:);
disp(val)
end
RE: help:how to generate different combinations of a sequence
RE: help:how to generate different combinations of a sequence
RE: help:how to generate different combinations of a sequence
can anyone help me with this
RE: help:how to generate different combinations of a sequence
It doesn't scale too well though. Each selection will require a longer search back through those already used.
RE: help:how to generate different combinations of a sequence
is there any alternative way of doing this other than perms approach.
can anyone help me with this.
RE: help:how to generate different combinations of a sequence
RE: help:how to generate different combinations of a sequence
RE: help:how to generate different combinations of a sequence
1. Start loop
2. Generate a random permutation
3. Check to see if you have used that permutation before (very unlikey for permutations of 40 elements)
4. do whatever you have to do with that sequence
5. store the sequence in (or a uniquely coded version of it) in the checklist
6. end loop
M
--
Dr Michael F Platten