Get array of elements based on occurrences of another vector
显示 更早的评论
Hi guys!
Let's assume that you have 2 Nx1 arrays "y" and "x", is there a way to find all the elements of y corresponding to the unique elements of x?
E.g
y=[0;1;2;3;4];
x=[1;1;2;2;2];
%The results should be two vectors, one containing the elements [0;1] and the other one containing
%[2;3;4]
Thank you!
采纳的回答
更多回答(1 个)
y=[0;1;2;3;4];
x=[1;1;2;2;2];
z=splitapply(@(x){x},y,x);
z{:}
类别
在 帮助中心 和 File Exchange 中查找有关 Data Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!