Edit matrix with condition

51 Ansichten (letzte 30 Tage)
Ravi Kumar
Ravi Kumar am 9 Mär. 2023
Beantwortet: Voss am 9 Mär. 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 Kommentar
Torsten
Torsten am 9 Mär. 2023
Using the same index j for the position in your new matrix as in your original matrix should be wrong.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Voss
Voss am 9 Mär. 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);

Weitere Antworten (0)

Kategorien

Mehr zu Quantum Mechanics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by