How can I improve this line of code perfomance wise?

4 ビュー (過去 30 日間)
lit
lit 2023 年 8 月 8 日
コメント済み: lit 2023 年 8 月 8 日
When using the profiler to look at the performance of a function I need to work with, I saw that one line takes up much time
invalidIndex = any((coords<ddims(1:3)) | (coords>ddims(4:6)),2);
So it just checks if the point contained are within the bounds. The size of coords is nx3
Is there any way this line can be improved perfomance wise. I couldn't think of anything else...
  2 件のコメント
Walter Roberson
Walter Roberson 2023 年 8 月 8 日
You could try unvectorizing it and seeing how much difference that makes:
invalidIndex = coords(:,1)<ddims(1) | coords(:,2)<ddims(2) | coords(:,3)<ddims(3) | coords(:,1)>ddims(4) | coords(:,2)>ddims(5) | coords(:,3)>ddims(6);
My expectation is that this would be notably slower... but that you would have to measure the timing to be sure.
lit
lit 2023 年 8 月 8 日
actually, it does improve performance, so thank you very much!

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by