YALMIP constraint - All values should be equal
Mostra commenti meno recenti
I am solving a optimization problem with different constraints and objectives using YALMIP. One of the constraints should be the following: The entries in the second row of my 3D matrix should have the same values in every third dimension. At the moment I am doing this with a for loop in the following way:
P = sdpvar(122,7,8);
Constraints = [];
for i = 2:8
Constraints = [Constraints, P(2,:,1) == P(2,:,i)];
end
So in other words this is what I want: P(2,1,1) should be the same value as P(2,1,2) and P(2,1,3) and ... and P(2,1,8). Moreover P(2,2,1) should be the same value as P(2,2,2) and P(2,2,3) and ... and P(2,2,8). And so on. But P(2,1,1) does not have to be equal to P(2,2,1) for example!
I am quite sure that the code stated above applies the constraint correctly. Is there however a better way of implementing this without a for-loop?
Or in a more general formulation: Is there a nice way of constraining all elements of a certain dimension to be the same value? Notice that this could even be a 2D matrix or a vector, the question remains the same.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!