How to vectorize finding the closest point out of a vector

前端 未结 3 1599
离开以前
离开以前 2021-01-15 04:16
BigList = rand(20, 3)
LittleList = rand(5, 3)

I\'d like to find for each row in the big list the \'closest\' row in the little list, as defined by

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-15 05:09

    You can do it with bsxfun:

    d = squeeze(sum((bsxfun(@minus, BigList, permute(LittleList, [3 2 1]))).^2, 2));
    [~, ind] = min(d,[],2);
    

提交回复
热议问题