Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
how to speed up this nestled for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi everybody,
I need to make this code faster:
for i=1:n1*n2*n3;
x1 = M(i,1);
y1 = M(i,2);
ex1 = M(i,4);
ey1 = M(i,5);
ez1 = M(i,6);
if x1 <= 70 && x1 >= -70 && y1 <= 70 && y1 >= -70;
ex2 (i) = 0;
ey2 (i) = 0;
ez2 (i) = 0;
else
ex2 (i) = ex1;
ey2 (i) = ey1;
ez2 (i) = ez1;
end
end
What is the best way to do that?
0 comentarios
Respuestas (3)
Andrei Bobrov
el 17 de Feb. de 2012
try this is code
exyz = zeros(size(M(:,4:6)));
t = all(M(:,1:2) >= -70 & M(:,1:2) <= 70,2);
exyz(t,:) = M(t,4:6);
ADD
so?
exyz2 = zeros(size(M(:,4:6)).*[1 2]);
t = all(M(:,1:2) >= 70 & M(:,1:2) <= 70,2);
exyz2(:,1:3) = M(:,4:6);
exyz2(t,4:6) = M(t,4:6);
ADD2
out = M;
t = all(M(:,1:2) >= 70 & M(:,1:2) <= 70,2);
out(t,4:6) = out(t,4:6);
0 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!