Shuffling ones in a column

1 次查看(过去 30 天)
Tim
Tim 2012-10-11
Hi,
I have a binary matrix, which looks like this:
1 1 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
0 0 1 1 1 1
0 0 0 1 1 1
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 1 1
0 0 0 0 0 1
0 0 0 0 0 1
What should I do when I want to shuffle the fixed amount of ones in one of the columns?
For instance, in an array the shuffling could look like this: 1111000000 --> 0001100101.
I guess this is quite a basic question, but I wasn't able to find the answer anywhere. Thanks in advance!
Cheers, Tim

采纳的回答

Matt J
Matt J 2012-10-11
If you want things shuffled uniformly/randomly, you could use randperm. Here's an example,
>> E='11110000';
>> E(randperm(8))
ans =
01000111
  2 个评论
Tim
Tim 2012-10-11
Thanks! Works like a charm :)
Syed Imam
Syed Imam 2012-11-8
how to de-randomize the data to get back to original data ?? >> E='11110000'; >> E(randperm(8)) ans = 01000111 (WORKS FINE TO RANDOMIZE THE DATA)
how to de-randomize the randomized data to get the answer '11110000'

请先登录,再进行评论。

更多回答(1 个)

Syed Imam
Syed Imam 2012-11-8
>> E='11110000'; >> E(randperm(8)) ans = 01000111 (WORKS FINE TO RANDOMIZE THE DATA)
how to de-randomize the randomized data to get the answer '11110000'

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by