フィルターのクリア

Efficiently find a value in a matrix

3 ビュー (過去 30 日間)
John Gilmore
John Gilmore 2021 年 3 月 26 日
コメント済み: John Gilmore 2021 年 3 月 29 日
Hey all,
So I have a simple 1D matrix that I'm trying to find a specific value in. I know of a way to do it, but my main question is if anyone knows of a more effcient way? As of current, I'm using as part of an operation that occurs on the order of millions or even billions of times, and using the matlab profiler it's told me that this is far and beyond the most inefficient part of the whole process.
This is how I currently do it...the third line take up ~60% of my run time
DummyData = [1,3,5,7,9];
ValueToFind = 3;
[~,Index] = min(abs(DummyDaya - ValueToFind));
  2 件のコメント
Stephen23
Stephen23 2021 年 3 月 26 日
If you want to "find a specific value" why are you using code that just finds the closest value?
John Gilmore
John Gilmore 2021 年 3 月 29 日
Ah yes, sorry, I should have been a bit more clear. This is doing what I want, particularly that's finding a specific value if it exists in the matrix. If it doesn't exist, then it finds the closest one.

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

採用された回答

weikang zhao
weikang zhao 2021 年 3 月 27 日
From the perspective of computational complexity, your code can no longer be optimized. You can seek help from GPU acceleration or parallel computing.
  1 件のコメント
John Gilmore
John Gilmore 2021 年 3 月 29 日
Yeah, that's sort of what I was unfortunately figuring. I guess I was wondering if anyone knew of more effcient built in functions, or maybe the built in functions have some bloat to them to make them more robust and someone knew of a smarter way to achieve the same result without using built-in functions.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by