Error using unique command
조회 수: 5 (최근 30일)
이전 댓글 표시
I have two values
A = [1000 16000 100000 30000 2000]
B = [150 100 4000 5000 2000];
I used code below to get the Sorted value of B according to A:
[ii jj k] = unique(A);
B = unique(B);
P = B(k);
C = [100 4000 2000 5000 150];
If my values of A are from -400 to 400 and and values of B are from -100 to 100 I get the error :
Index exceeds Dimension
Please provide assistance.
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2012년 11월 24일
편집: Azzi Abdelmalek
2012년 11월 24일
Edited
A=[1000 16000 100000 30000 2000]
B=[150 100 4000 5000 2000];
[~,idx]=sort(A)
[~,idx1]=sort(idx)
C=B(idx1)
댓글 수: 21
Azzi Abdelmalek
2012년 11월 24일
편집: Azzi Abdelmalek
2012년 11월 24일
or maby it's this
A=[1000 16000 100000 30000 2000]
B=[150 100 4000 5000 2000];
[~,idx]=sort(A)
[~,idx1]=sort(idx)
C=B(idx1)
추가 답변 (2개)
Salil Goel
2012년 11월 24일
Are you making sure that the size of A and B is same when values in A are from -400 to 400 and B from -100 to 100? If not, then obviously you would get this error.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!