How to generate a a restricted binary number
이전 댓글 표시
Dear friends
I would like to generate a random number include 24 bits 4 bits of 1 and 20 bits of 0. Can you help me?
Best Regards
Mohsen
채택된 답변
추가 답변 (1개)
댓글 수: 2
I do not understand what "number dimension, max and min" means. Maximum and minimum of what? My answer includes a method to create random vectors already:
v = zeros(1, 24);
v(randperm(24, 4)) = 1;
Do you now want to create all these vectors? Then:
M = nchoosek(1:24, 4);
for k = 1:size(M, 1)
v = zeros(1, 24);
v(M(k, :)) = 1;
...
end
Mohsen
2018년 12월 6일
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!