Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
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 commentaires
Matt J
Matt J le 25 Jan 2019
What do you mean by "frequency"? They all have unique values.
tushar bhonsle
tushar bhonsle le 26 Jan 2019
yes i know, but how to calculate and store in an array thrugh programming.

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 25 Jan 2019
Modifié(e) : Matt J le 25 Jan 2019
n=numel(yourVector);
mask=dec2bin(0:2^n-1,n)-'0';
mask(1,:)=[];
combs= mask*yourVector(:) ;
result = histcounts( combs , 1:max(combs)+1);
  4 commentaires
Stephen23
Stephen23 le 26 Jan 2019
Modifié(e) : Stephen23 le 26 Jan 2019
@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 le 26 Jan 2019
Thanks, It's working but still how can i store in array and write output in excel file.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by