I would like to create a new vector which contains values from b which correspond to the closest values from a. I mainly code in python and am new to Matlab. The only thing i can think of at the moment is an if statement which i know would most likely be inefficient. Essentially i would need to create new vectors for each value in a. The following is my code. Any help is greatly appreciated, thanks in advance.

`a=[1250 2320 3520 7650];b= [3700 6766 8888 1212 2000 5555 9998 3000];vals=zeros(7,1);n=1;for i = b differences = abs(a-i); [minDiff, indexOfMinDiff] = min(differences); closestValue = a(indexOfMinDiff); vals(n)= closestValue; n=n+1;endedges = unique(vals)counts = histc(vals(:), edges)`

## Best Answer