Consider three row vectors in Matlab, A
, B
, C
, each with size 1xJ
. I want to construct a matrix D
of size Kx3
listing every triplets (a,b,c)
such that:
a
is the position inA
ofA(a)
.b
is the position inB
ofB(b)
.A(a)-B(b)
is an element ofC
.c
is the position inC
ofA(a)-B(b)
.A(a)
andB(b)
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=[1 1 3; %-3-(-2)=-1
2 2 4; % 3-2=1
3 3 5]; % 0-0=0
I would like this code to be efficient, because in my real example I have to repeat it many times.
This question relates to my previous question here, but now I'm looking for the positions of the elements.