Edit matrix with condition
51 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Torsten
le 9 Mar 2023
Using the same index j for the position in your new matrix as in your original matrix should be wrong.
Réponse acceptée
Voss
le 9 Mar 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);
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Quantum Mechanics dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!