How do I get the position of the highest numbers of a vector?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everyone,
Does anyone know how to get the position of 4 highest numbers of a vector? For example,
rng(1)
a = randn(10,1)
a =
-0.6490
1.1812
-0.7585
-1.1096
-0.8456
-0.5727
-0.5587
0.1784
-0.1969
0.5864
Clearly the four highest numbers are 1.1812 , 0.5864 , 0.1784 and -0.1969. That correspond to element 2,10,8 and 9, respectively. How can I get this sequence in a vector form, ie 4x1?
Thanks a lot.
댓글 수: 0
채택된 답변
dpb
2017년 4월 9일
>> [mx,ix]=sort(a,'descend');
>> N=4;
>> num2str([ix(1:N) mx(1:N) ],'Posn %2d Value %7.4f')
ans =
Posn 2 Value 1.1812
Posn 10 Value 0.5864
Posn 8 Value 0.1784
Posn 9 Value -0.1969
>>
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!