How to generate all pairwise differences between two vectors

19 views (last 30 days)
Hi,
how can I generate a new vector of all the pairwise differences between two existing vectors?
thanks,
Tamir

Answers (4)

Andrei Bobrov
Andrei Bobrov on 6 Feb 2019
out = a(:) - b(:)';

Tamir Eisenstein
Tamir Eisenstein on 7 Feb 2019
Thanks Andrei!

Tamir Eisenstein
Tamir Eisenstein on 15 Feb 2019
Edited: Tamir Eisenstein on 15 Feb 2019
Hi Andrei, I have a small follow-up question:
How can I generate each difference value in "out" to be a percentage from b [i.e ((a-b)/b)*100 ] and not as a "raw" value?
Thanks!
Tamir

Andrei Bobrov
Andrei Bobrov on 15 Feb 2019
out = (a(:)' - b(:))./b(:)*100;

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!