Finding pairs in (not equidistant) time series
Type parameter:
'l': only lower neighbors accepted
'u': only upper neighbors accepted
'n' or not given: nearest (upper or lower) neighbors selected
If there is no neighbor for x(i), y2(i)=idx(i)=NaN is returned.
Options:
'self': y2(i)==x(i) [zero distance] is accepted as 'neighbor'
'unique': if i<>j and y2(i)==y2(j), y2(i)=y2(j)=NaN is returned
Example:
x= [ 2 5 7 9 10 12];
y= [1 3 4 6 8 11];
[y2 idx2]=nearest(x,y,'l','unique')
[y3 idx3]=nearest(x,y,'u')
Results:
y2=[1 4 6 NaN NaN 11] idx2=[1 3 4 NaN NaN 6]
y3=[3 6 8 11 11 NaN] idx3=[2 4 5 6 6 NaN]
Cite As
Peter Csordas (2023). Finding pairs in (not equidistant) time series (https://www.mathworks.com/matlabcentral/fileexchange/40026-finding-pairs-in-not-equidistant-time-series), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- AI, Data Science, and Statistics > Statistics and Machine Learning Toolbox > Cluster Analysis > Nearest Neighbors >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |