Pairwise difference between values of a vector
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Itai
le 29 Juil 2012
Réponse apportée : James Cai
le 31 Jan 2018
Hello all, I want to calculate the mean of all absolute pairwise differences (Ei-Ej) from a long set of values. for example (3 1 2) the differences are 3-1=2, 3-2=1, 1-2=1 and the mean (2+1+1)/3=1.33. Thanks for helping
0 commentaires
Réponse acceptée
the cyclist
le 29 Juil 2012
One way:
% The data
v = [3 1 2];
% Number of elements
nv = numel(v);
% Absolute pairwise diifferences
dv = abs(bsxfun(@minus,v,v'));
% Sum the differences (This double-counts, but we'll double-count the denominator, too)
sdtv = sum(dv(:));
% Number pairs (also double-counted)
np = nv^2 - nv;
% The mean
mdtv = sdtv/np
0 commentaires
Plus de réponses (1)
James Cai
le 31 Jan 2018
Nowadays, dv = abs(v-v') returns the absolute pairwise differences.
0 commentaires
Voir également
Catégories
En savoir plus sur Argument Definitions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!