Make Matlab search for the closest match to a given pattern within a matrix?
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!