How to Find Index of Repeated Elements in a Vector?
조회 수: 9 (최근 30일)
이전 댓글 표시
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
채택된 답변
Jan
2021년 3월 8일
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!