Y
Posts:
2
Registered:
6/9/13
|
|
match matrix to closest values
Posted:
Jun 9, 2013 6:50 PM
|
|
Here's a function I wrote. It creates a matrix with the same dimensions as 'needle', placing in each element the closest value from 'haystack':
function [val] = closest(haystack, needle) [~, i] = min(abs( ... repmat(reshape(haystack,numel(haystack),1),1,numel(needle)) - ... repmat(reshape(needle,1,numel(needle)),numel(haystack),1) ... ), [], 1); val = reshape(haystack(i), size(needle)); end
I'd appreciate suggestions & improvements.
-- kwikwag
|
|