Edit matrix with condition

1 view (last 30 days)
Ravi Kumar
Ravi Kumar on 9 Mar 2023
Answered: Voss on 9 Mar 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 Comment
Torsten
Torsten on 9 Mar 2023
Using the same index j for the position in your new matrix as in your original matrix should be wrong.

Sign in to comment.

Accepted Answer

Voss
Voss on 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);

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!