0

I'm using the matlab package "CVX" to solve an optimization problem. Currently I'm using a for loop to add the constraints, but I found that it is extremely slow when initializing the problem.

for i=1:n
    norm(Nout(i,:)-Nin(i,:))<=tau;
end

Nout and Nin is two matrix of size n*3, and I need the norm of each row of the matrix Nout-Nin is smaller than a threshold, how could I write this without loops? Thanks!

Leo 254
  • 181
  • 1
  • 8
areslp
  • 383
  • 1
  • 4
  • 17

1 Answers1

0

You can compute the norm manually:

result = sqrt(sum((Nout - Nin) .^ 2, 2)) <= tau
Eitan T
  • 32,660
  • 14
  • 72
  • 109