New variable based on a 'percentile' condition
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a double variable A with 6000 rows and 3 columns:
- C1 gives the year;
- C2 gives a code (no repetitions within each year);
- C3 gives a number;
C1 C2 C3
A=[1983 11 54
1983 13 24
1983 16 32
1983 20 11
1983 25 14
1983 28 23
1983 29 19]
B, is a cell variable with 1 row and 31 columns (each column corresponds to a year) that gives the 90th percentile of A(:,3) per year:
B={53 49.3 51.7 49.2 48 40 41 44.6 …}
I am trying to obtain a new variable A2 that would be equal to A, but would only consider the cases in which A(:,3) > B(1,:).
For example, I have already done something similar but with different conditions, only in these cases my condition would not change from year to year:
numMean=A(A(:,3)>=42.8,[1 2 3]);
num25=A(A(:,3)>=25,[1 2 3]);
Thank you very much for your help.
채택된 답변
Azzi Abdelmalek
2014년 8월 26일
편집: Azzi Abdelmalek
2014년 8월 26일
B={53 49.3 51.7 49.2 48 40 41}
A=[1983 11 54
1983 13 24
1983 16 32
1983 20 11
1983 25 14
1983 28 23
1983 29 19]
out=A(all(bsxfun(@gt, A(:,3),cell2mat(B)),2),:)
댓글 수: 0
추가 답변 (1개)
Kelly Kearney
2014년 8월 26일
Could do it all it one step with accumarray. Though this way doesn't preserve the initial order... not sure if that is necessary or not for your task.
% Fake data
n = 100;
A = [floor(rand(n,1)*5) + 1983 ones(n,1) round(rand(n,1)*100)];
% Find values >90% of their year
[unqyr, blah, ia] = unique(A(:,1));
nyr = length(unqyr);
atop = accumarray(ia, A(:,3), [nyr 1], @(x) {x(x > prctile(x,90))});
cell2mat(atop)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!