Edit matrix with condition

3 visualizaciones (últimos 30 días)
Ravi Kumar
Ravi Kumar el 9 de Mzo. de 2023
Respondida: Voss el 9 de Mzo. de 2023
I have a large matrix of position & velocities of multiple particles:
I need to create a similar new matrix with a condition on radial location (column 7)
for example:
If my particle radial location (column 7) is beween 0.0100 to 0.0115, create a new matrix with corresponding position & vecloties (column 1,2,3&4).
X Y Vx Vy Frame Particle RadialLocation
I have tried but it is very slow!
my matrix size is large ~ (4200000 * 7)
if (mm(j,7) <= 0.0115) && (mm(j,7) > 0.0100)
p_n(j,1) = mm(j,1);
p_n(j,2) = mm(j,2);
v_n(j,1) = mm(j,3);
v_n(j,2) = mm(j,4);
else
p_b(j,1) = mm(j,1);
p_b(j,2) = mm(j,2);
v_b(j,1) = mm(j,3);
v_b(j,2) = mm(j,4);
end
  1 comentario
Torsten
Torsten el 9 de Mzo. de 2023
Using the same index j for the position in your new matrix as in your original matrix should be wrong.

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 9 de Mzo. de 2023
idx = mm(:,7) <= 0.0115 & mm(:,7) > 0.01;
p_n = mm(idx,1:2);
v_n = mm(idx,3:4);
p_b = mm(~idx,1:2);
v_b = mm(~idx,3:4);

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by