Given a vector A, return the matrix B, wherein each row contains a permutation of the unique values in original vector while retaining the original order of A. Permutations should operate on repeated numbers in indexed order.
For example, if A = [2 5 3 4 2 1 3], the function should return:
[2 5 3 4 1;
2 5 4 1 3;
5 3 4 2 1;
5 4 2 1 3]
This result is due to two repeated values: 2, at indices 1 & 5 and 3, at indices 3 & 7. The permutations of repeated numbers to include are then:
1 3 (i.e., remove elements at indices 5 & 7, resulting in [2 5 3 4 1])
1 7 (i.e., remove elements at indices 3 & 5, resulting in [2 5 4 1 3])
5 3 (i.e., remove elements at indices 1 & 7, resulting in [5 3 4 2 1])
5 7 (i.e., remove elements at indices 1 & 3, resulting in [5 4 2 1 3])
Solution Stats
Problem Comments
3 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers17
Suggested Problems
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
2052 Solvers
-
given 3 sides, find area of this triangle
821 Solvers
-
Omit columns averages from a matrix
620 Solvers
-
Implement simple rotation cypher
1098 Solvers
-
Output any real number that is neither positive nor negative
410 Solvers
More from this Author3
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
The problem title and description have been improved.
What should the behavior be when a certain value occurs three times or more in vector A? For example, when A = [2 5 3 4 2 1 3 2] (which is the same as the A in the problem description, but with another '2' added to the end), should matrix B list [5 4 2 1 3] before [5 3 4 1 2], or after?
The problem would be more interesting with a test case having more than 2 repeating elements.