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에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!