How to Find Index of Repeated Elements in a Vector?
9 views (last 30 days)
Show older comments
I have a vector, for example:
x = [7, 22, 16, 20, 22, 3, 6, 22, 5]
I would like to first look the nth element of the vector, and then check the other indices to see if this value is repeated.
For example:
x(5) = 22.
How would I find the other indices of x which are also 22? In this example, I would expect a return of x(2) and x(8).
0 Comments
Accepted Answer
Jan
on 8 Mar 2021
x = [7, 22, 16, 20, 22, 3, 6, 22, 5]
index = 5;
a = x(5)
index = find(x == a)
% Or:
[UniqX, iX, iUniqX] = unique(x)
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!