Pairwise row difference between two matrices

This is a problem related to the following link:

Instead of seeking the pairwise difference between two vectors, I would like to find the pairwise row difference of two matrices where:

  • xpos is a matrix of N_pos by d
  • xneg is a matrix of N_neg by d
  • and I want to find the pairwise row difference between the two matrices

Therefore, the end result is a matrix of (N_pos * N_neg) by d.

I know I can do the followingin matlab but it seems not efficient enough:

for i = 1:size(xpos,1)
for j = 1:size(xneg, 1)
xpos_minus_xneg = [xpos_minus_xneg; xpos(i, :slight_smile: - xneg(j, :)];

Is there any way I can enter such formulation in cvx? Many thanks!