How to find indices of similar values in a vector?
10 次查看(过去 30 天)
显示 更早的评论
I want to get the indices of similar values in a vector. For example, I have a vector x=[1 1 2 2 3]. The output should be something like this: indices = 1,2 & 3,4
1 个评论
Jan
2017-8-1
Duplicate question, see https://www.mathworks.com/matlabcentral/answers/351130-how-to-find-indices-of-similar-elements-in-a-vector
@Syed Fahad Hassan: Please post a question only once.
采纳的回答
Rob Campbell
2017-8-1
编辑:Rob Campbell
2017-8-1
I'm unsure if you're looking for sequential numbers or not. The following just looks for repeats. Does it do what you want?
x = [1,1,2,2,3,4,5,6,1,2,3];
% Store in a cell array the indexes of values that repeat
reps={};
for thisU=unique(x)
f=find(x==thisU);
if length(f)>1, reps{end+1}=f; end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!