Subtracting multiple vectors from each row of an array (super broadcasting)
问题 I have a data set, X that is m x 2 , and three vectors stored in a matrix C = [c1'; c2'; c3'] that is 3 x 2 . I am trying to vectorize my code that finds, for each data point in X , which vector in C is closest (squared distance). I would like to subtract each vector (row) in C from each vector (row) in X , resulting in an m x 6 or 3m x 2 matrix of differences between the elements of X and the elements of C . My current implementation does this one row in X at a time: for i = 1:size(X, 1)