New variable based on a 'percentile' condition
2 ビュー (過去 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!