フィルターのクリア

How can I make indexing faster, that is, searching for a groups of numbers within a matrix?

1 回表示 (過去 30 日間)
Hello!
I was wondering if there was anything faster than this:
X = ( Y1 < a & Y1 >= b & Y2 >= c & Y2 < d );
I run it in a loop a lot and it is by far taking up the most time. X is a group of numbers that meets 4 conditions. I am searching two large matrices, Y1 and Y2 for numbers that meets that condition. Anyone have an easier way?
I am on Matlab 2015a, 64bit, 120GB Ram, and blazing fast processors.
Thanks!
  11 件のコメント
James Tursa
James Tursa 2015 年 6 月 9 日
Use the edited version.
Joe
Joe 2015 年 6 月 15 日
James,
I implemented this code and it reduced the time it takes to run that code ~50 - 80%!! Great! Thank you very much. I am now looking at mex'ing other lines of code to get (hopefully) similar speed ups. Thanks again!

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

採用された回答

Walter Roberson
Walter Roberson 2015 年 6 月 5 日
In the special case that a relatively small fraction satisfies one of the conditions, and letting letting C1, C2, C3, C4 be the conditions ranked from least to most probable, such as C1 being "Y1 >= B", then you might try:
X( (((sparse(C1) & C2) & C3) & C4 )
for example
X( ((sparse(Y1 >= B) & (Y2 < d)) & (Y2 >= c)) & (Y1 < a) )
I don't promise it will be faster, but in theory it could be.
Note: this has more overhead than the way you used, so your occupancy needs to b less than... ummm, perhaps 1/4 maybe... before this gets speedup.
  1 件のコメント
Joe
Joe 2015 年 6 月 5 日
Walter -
I implemented this and got 20% speed up! Great suggestion!
Thanks, Joe

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by