find few elements in vector
3 次查看(过去 30 天)
显示 更早的评论
Hi!
Let's assume that I have a vector y=[3 5 6 7 9] and x=[5 9] How can I get the indices of elements in 'y' that are equal to 'x' without using cycle? I mean if I had x=5 ('x' is a scalar) I would write something like y==x or find(y==x) but 'x' is a vector. Thank you in advance
0 个评论
采纳的回答
更多回答(2 个)
Roger Stafford
2016-11-15
[~,ia] = intersect(y,x);
ia contains indices with respect to y of elements that lie both in y and in x.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!