I have 4 bits combinations, and I want to change the size of the matrix HT depending on these combinations, the description below
조회 수: 2 (최근 30일)
이전 댓글 표시
First ___ I creat the combinations like the follow:
n=4; %number of bits
r = [ 0:2^n-1 ];
A = [];
for i = 1 : n
A = [A;r];
end
c = [];
for i = 0 : n-1
c = [ 2^i c ];
end
c = c';
B = [];
for i = 1 : 2^n
B = [B c];
end
A=sign(bitand(A,B))'
Second_____
%A matrix has in each row 4 bits : 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
HT=(n,3); % the rows of HT is equal to the number of bits
When the bit combination is 0001 then HT will have one row (the last one) and When the bit combination is 0110 HT will have two rows (the second and the third one), also I think When the bit combination is 0000 it's better to put HT equal to zero;
채택된 답변
DGM
2021년 6월 12일
편집: DGM
2021년 6월 12일
Not sure how you want to handle HT, but here goes:
n = 4; %number of bits
% don't need all those loops
A = dec2bin(0:2^n-1)=='1' % should be in base toolbox
% assuming HT already exists
HT = randi(9,n,3)
% idk how you want to handle a bunch of different-sized arrays
% i'm just going to throw them all in one cell array
HT_out = cell(size(A,1),1);
for r = 1:size(A,1)
thisHT = HT(A(r,:),:);
if isempty(thisHT)
HT_out{r} = [0 0 0];
else
HT_out{r} = thisHT;
end
end
format compact
celldisp(HT_out)
(scroll to see the rest of HT_out)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!