How to find values in a vector that are correspond to the 6th biggest values in another related vector?

조회 수: 2 (최근 30일)
There are two vectors, the 1st one is named peaks and the 2nd one is named frequencies and they are related to each other (I mean each value in the frequency vector is related to the value in the peaks vector).
How can I find the values in the frequency vector that are correspond to the biggest 6 values in the peaks vector?
**Note: I need the frequency values all by one time not one to one !

채택된 답변

Keshav
Keshav 2022년 7월 5일
you can use the below code and made the change according to you.
basically idx will store the index corresponding to the sorted order of peak.
so idx(6) is the index of 6th largest element in peak. so now you can find the frequency of the element correspoding to index idx(6)
fre = [5 1 4 3 2 7 8 9];
peak =[9 2 8 6 4 3 2 11];
[newP,idx] = sort(peak,"descend");
fre(idx(6))
  댓글 수: 3
Keshav
Keshav 2022년 7월 5일
편집: Keshav 2022년 7월 5일
I misinterpret your question and thought you want only 6th value. If you want top 6 value of frequency based on peak, the below code will work.
fre(idx(1:6))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by