Shuffling ones in a column

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일

1 개 추천

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일

0 개 추천

>> 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'

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

Tim
2012년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by