How to Permute the array with specific number?
Show older comments
I want to keep 1,2,6,7,9,10, they will not move
I have this array
b=[1,5,2,8,6,11,7,9,3,10]
P=perms(b);
HOw to use perms for 3,5,8,11 among 6 numbers above?
Accepted Answer
More Answers (1)
You did not mention how the output should look like. Perhaps:
b = [1,5,2,8,6,11,7,9,3,10];
keep = [1,2,6,7,9,10];
move = ~ismember(b, keep);
P = perms(b(move));
R = repmat(b, size(P,1), 1);
R(:, move) = P
6 Comments
Jan
on 29 May 2019
@Hang Vu: If I assume, that your examples contain some typos, the output R contains all wanted vectors as rows. So is your problem solved?
Hang Vu
on 29 May 2019
Jan
on 29 May 2019
@Hang Vu: I do not understand, what you mean. You solved the problem, but this is another one? Is the problem of your question solved or not?
"if the moving numbers move then you will see the keeping move..." - what does this mean?
Please explain exactly, what you want to achieve.
Hang Vu
on 29 May 2019
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!