Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Star Strider
Star Strider am 17 Mär. 2015
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’.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by