필터 지우기
필터 지우기

I have an array of n elements like [1 2 4 8 16]. I want calculate frequency of all combinations. 1, 2 ,4 ,8, 16, 1+2, 1+4, 1+8, 1+16, 2+4, 2+8, 2+16, 4+8, 4+16, 8+16, 1+2+4, 1+2+8, 1+2+16, 1+2+4+8, 1+2+4+16, 1+2+4+8+16 How can i store output in array

조회 수: 2 (최근 30일)
1, 2 ,4 ,8 ,16
1+2, 1+4, 1+8, 1+16,
2+4, 2+8, 2+16,
4+8, 4+16,
8+16,
1+2+4, 1+2+8, 1+2+16,
1+2+4+8, 1+2+4+16,
1+2+4+8+16

채택된 답변

Matt J
Matt J 2019년 1월 25일
편집: Matt J 2019년 1월 25일
n=numel(yourVector);
mask=dec2bin(0:2^n-1,n)-'0';
mask(1,:)=[];
combs= mask*yourVector(:) ;
result = histcounts( combs , 1:max(combs)+1);
  댓글 수: 4
Stephen23
Stephen23 2019년 1월 26일
편집: Stephen23 2019년 1월 26일
@tushar bhonsle: if you are using a MATLAB version prior to R2014b, then you will not have histcounts and will need to use histc instead, e.g.:
V = [1,2,4,8,16]
N = numel(V);
M = dec2bin(1:2^N-1)-'0';
C = M*V(:)
Z = histc(C, 1:max(C)+1)
@Matt J: surely it is easier to start from 1 than to delete the first row?
tushar bhonsle
tushar bhonsle 2019년 1월 26일
Thanks, It's working but still how can i store in array and write output in excel file.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by