Filter matrix rows depending on values in a second matrix

后端 未结 3 1894
旧巷少年郎
旧巷少年郎 2020-12-04 03:38

Given a 2x3 matrix x and a 4x2 matrix y, I\'d like to use each row of y to index into x. If the value in x i

3条回答
  •  既然无缘
    2020-12-04 04:32

    This can be easily vectorized as follows (see sub2ind):

    y = y(x(sub2ind(size(x), y(:,1), y(:,2)))==-1,:);
    

提交回复
热议问题