Recoding unique numbers to another number
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi I have this array of numbers [5 5 6 6 6 11 11 ]and would like to convert every unique number from 1 to n. For example, if there are 10 unique numbers, I would like to relabel them from 1 to 10, with the same number coded the same for eg [1 1 2 2 2 3 3]
The actual array is attached here. How may I code for this? Thanks so much!
댓글 수: 0
채택된 답변
Stephen23
2020년 12월 28일
The simple and efficient MATLAB solution:
X = [5,5,6,6,6,11,11];
[~,~,Z] = unique(X,'stable')
댓글 수: 0
추가 답변 (2개)
KALYAN ACHARJYA
2020년 12월 28일
편집: KALYAN ACHARJYA
2020년 12월 28일
data=[5 5 6 6 6 11 11];
counts=histc(data,unique(data));
data_result=repelem(1:length(unique(data)),counts)
Results:
data_result =
1 1 2 2 2 3 3
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!