MATLAB: Compare two arrays of different length

arrayvectors

I have two arrays. Lets say A = [1 5 7 10 14 17 19 22 25 26 29], B= [2 7 12 18 23 ] I want to find out the values / positions in A which are nearest to every value of B.
P.S : The resulting array should have the same length as B. Any suggestions are welcome.
Thanks

Best Answer

[junk, Aidx] = min(abs(bsxfun(@minus,A.',B)));