フィルターのクリア

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
  2 件のコメント
Matt J
Matt J 2019 年 1 月 25 日
What do you mean by "frequency"? They all have unique values.
tushar bhonsle
tushar bhonsle 2019 年 1 月 26 日
yes i know, but how to calculate and store in an array thrugh programming.

サインインしてコメントする。

採用された回答

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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by