フィルターのクリア

Make Matlab search for the closest match to a given pattern within a matrix?

1 回表示 (過去 30 日間)
Peta
Peta 2015 年 3 月 17 日
回答済み: Star Strider 2015 年 3 月 17 日
If I have a data set of something that occurred during a day, for example stored in a 550x1 variable. Could I use it as a target data set to search through a much bigger matrix containing the same type of values but during an entire year, for example a 550x365 matrix and have Matlab tell me where the closest matching (with the same length) pattern occurred? Is there a function for that?
Note that I’m not looking for an exact match, what I’m looking for might not even be even close to a 100% match. But can Matlab identify what would be classified as the closest match? And perhaps even give me some sort of confidence value of how good the match was?

採用された回答

Star Strider
Star Strider 2015 年 3 月 17 日
If you have the Statistics Toolbox, use the knnsearch function. If you don’t have it, the same algorithm is fairly easy to implement:
M = randi(10, 20, 5); % Search Matrix
T = randi(10, 1, 5); % Search Vector
for k1 = 1:size(M,1)
D(k1) = sqrt(sum((M(k1,:) - T).^2));
end
The index of the lowest value of ‘D’ is the index of the row in ‘M’ that is the closest match to ‘T’.

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by