adding constraints with if loop
Mostrar comentarios más antiguos
a1=1:.3:5.2;
b1=3:.2:5.8;
c1=2:.3:6.2;
for k=1:15
composite=[a1(:,k) b1(:,k) c1(:,k)];
origin=[1.3 1.1 1.5];
d(:,k)=sqrt(sum((composite-origin).^2));% 1*15 vector
end
But now in 'composite' I want to exclude those all points which have a1 less than or equal to 1.5, b1 greater than or equal to 5 and c1 less than or equal to 2. So now my d vector will be 1*6 instead of 1*15. How can I get this result with combination of for and if loop.
3 comentarios
Walter Roberson
el 3 de Feb. de 2012
There is no such thing as an "if loop"
Bibek
el 4 de Feb. de 2012
Walter Roberson
el 4 de Feb. de 2012
'S'ok. I'm just trying to prevent the phrase from spreading as several people started using it.
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 3 de Feb. de 2012
a1=1:.3:5.2;
b1=3:.2:5.8;
c1=2:.3:6.2;
composite=[a1(:), b1(:) c1(:)];
Lidx_a = a1 <= 1.5;
Lidx_b = b1 >= 5;
Lidx_c = c1 <= 2;
composite((Lidx_a | Lidx_b | Lidx_c),:) = [];
nrow = size(compisite,1);
origin=[1.3 1.1 1.5];
d = sqrt( sum( (composite-repmat(origin,nrow,1)).^2, 2) );
No loop needed.
The second argument to sum, the 2, is needed to sum along rows.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!