필터 지우기
필터 지우기

dec2bin ast n=25

조회 수: 1 (최근 30일)
Quynh tran
Quynh tran 2017년 6월 13일
댓글: Quynh tran 2017년 6월 14일
Dear all, I want to create a matrix including number 0 and 1. but only 10 number 1 in a row. for example:
A=[1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
......]
|but with command dec2bin, the limitation is only to n=20 because if n=25, it's over the memory of computer with this inform "Requested 1073741823x1 (8.0GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information". | Could we have another way to make this matrix. Thanks

채택된 답변

Walter Roberson
Walter Roberson 2017년 6월 14일
N = 20;
chunksize = 2^10; %must divide 2^N
ten1s = [];
for K = 0 : chunksize : 2^N - 1
this_chunk = K : K + chunksize - 1;
these_bits = dec2bin(this_chunk, N);
mask = sum(these_bits == '1', 2) == 10;
ten1s = [ten1s; uint8(these_bits(mask,:) - '0')];
end
  댓글 수: 1
Quynh tran
Quynh tran 2017년 6월 14일
you are amazing. thank you so much <3

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by