필터 지우기
필터 지우기

How to find the 12th highest value for every year

조회 수: 1 (최근 30일)
Nicky Benedict
Nicky Benedict 2021년 6월 7일
답변: Nicky Benedict 2021년 6월 9일
I have a data set that I have made into a table and used the sort funtion to make it into descending order based on the year followed by the 2nd column values i.e.
2014 3.98 10.34
2014 3.93 10.24
2014 3.90 10.18
.
.
.
2006 0.61 5.05
2006 0.54 5.01
2006 0.52 4.98
2006 0.50 4.89
2006 0.50 4.79
I want to find the 12th highest value for each year (the 12th row for every year).
The number of data measurements for each year are not equal. For example, in year 2014 there might be 12000 rows but in year 2010 there may only be 11500 rows of data
Thank you in advance.

채택된 답변

Nicky Benedict
Nicky Benedict 2021년 6월 9일
I figured it out.
T_sort = sortrows(T,[1,2,3],'descend');
[yr,index] = unique(T_sort.Years);
index_new = index + 11;
hour_12 = T_sort(index_new,:);

추가 답변 (1개)

SALAH ALRABEEI
SALAH ALRABEEI 2021년 6월 7일
Since you already sorted them, what you need to do now is call the first highest 12 as follows
% Assuming the matrix is A where the 1st col is the years.
B = [];
years = unique(A(:,1));
for i = 1: length(years)
B= [B,(A(A(:,1)==years(i),12))];
end
  댓글 수: 3
SALAH ALRABEEI
SALAH ALRABEEI 2021년 6월 9일
Sorry that was my mistake. Please add replace this wth what is inside the loop
%
btemp = A(A(:,1)==years(i),:);
B = [B ; btemp(12,:) ];
Nicky Benedict
Nicky Benedict 2021년 6월 9일
The approach you took ended up just giving me the years but I managed to figure it out with the help of the "unique" function you had in your code. Thank you for all your help. I appreciate it. I posted my code down below if you want to know what I did.

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

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by