Consider three row vectors in Matlab, A
, B
, C
, each with size 1xJ
. I want to construct a matrix D
of size Kx2
listing every possible pairs of elements (a,b)
such that:
a
is an element ofA
.b
is an element ofB
.a-b
is an element ofC
.a
andb
are different fromInf
,-Inf
.
For example,
A=[-3 3 0 Inf -Inf];
B=[-2 2 0 Inf -Inf];
C=[Inf -Inf -1 1 0];
D=[-3 -2; %-3-(-2)=-1
3 2; % 3-2=1
0 0]; % 0-0=0
I would like this code to be efficient, because in my real example I have to repeat it many times.