How can I get operating the code vector computing with different size matrix

I want to do vector operations.
When the initial position x = s, 1000 particles enter the function with different phases, they receive different E-fields through a while loop and reach the point x = 0. This will cause the loop to end at different points, causing an error.
I am wondering how to solve this problem.

 採用された回答

KSSV
KSSV 2021 年 3 月 9 日
Read about logical indexing. Pick the points or x which are not zeros and do the operations on only those points ignoring the points which have value zero or attained zero.
Some think like shown:
idx = x > 0 ;
x_nonzeros = x(idx) ;
% do the operations on x_nonzeros
x(idx) = x_nonzeros % fill the obtained value back in x at the indices

1 件のコメント

inho seong
inho seong 2021 年 3 月 10 日
Thanks for your reply.
Thanks to your comment, I could solve my problem vecterized.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2021 年 3 月 9 日

コメント済み:

2021 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by