Edit matrix with condition
51 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Torsten
2023 年 3 月 9 日
Using the same index j for the position in your new matrix as in your original matrix should be wrong.
採用された回答
Voss
2023 年 3 月 9 日
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 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!