I have a set of discrete values in the row vector <list>. I want to take a vector M of real doubles, and for each element M(j) in M I want to replace M(j) with the element in <list> that is closest to M(i) on the number line. For example, if my list was [2 4] and my matrix was [1.1, 3.2, 5, -17], the resulting matrix would be [2, 4, 4, 2].

I know I can do this with a for loop:

`for j=1:length(M) [m mn]=min(abs(list-M(j))); M(j)=list(mn);end`

Is there any way to do this without a for loop?

## Best Answer