Index from one vector to different sized vector
1 次查看(过去 30 天)
显示 更早的评论
I have a 582x1 column vector and a 3190x2 matrix. I want to extract only those rows of the matrix whose column 1 entry has the same value as any entry in the 582 vector. I can't figure out how to index in this way. I tried changing the size of the column vector to 3190, but it still only compared the entries with the same indexes.
0 个评论
采纳的回答
更多回答(1 个)
Asad (Mehrzad) Khoddam
2020-9-12
% v1 the first vector
% v2 the matrix
[~, ~, i2] = intersect(v1, v2(:,1));
newMatrix = v2(t2,:);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!