Append new column to a cell with zero & one values
2 ビュー (過去 30 日間)
古いコメントを表示
I have a cell type variable with thousand rows and 8 columns. For example:
c3
A={ 12 0 69.11 13 40 100 90602 1996
13 0 46.21 16 48 183 30502 1996
16 0 45.34 11 37 183 40701 1996
18 0 8.70 17 81 76 60110 1996
26 0 78.23 13 48 254 40301 1996
41 0 17.83 26 41 98 20501 1996
42 0 92.02 12 75 7 20502 1996};
Taking into account the third column (c3) I would like to append a new column to variable A that wil have the value of 1 if the value in c3 corresponds to the bottom 5th percentile of all the values in c3 and zero otherwise. Basiscally append dummy variable that gives 1 for 'scores' in the bottom 5% of the distribution (c3).
Can someone help me? Thank you.
2 件のコメント
the cyclist
2014 年 8 月 17 日
Is the notation in c3 such that the comma represents the decimal? "69,11" is a single value, equal to 69 + 11/100?
採用された回答
Adam
2014 年 8 月 17 日
pVal = prctile( [A{:,3}], 20 );
A(:,end+1) = {0}
A( [A{:,3}] <= pVal, end ) = {1}
I think that should do what you want.
0 件のコメント
その他の回答 (2 件)
the cyclist
2014 年 8 月 17 日
A = { 12 0 69.11 13 40 100 90602 1996
13 0 46.21 16 48 183 30502 1996
16 0 45.34 11 37 183 40701 1996
18 0 8.70 17 81 76 60110 1996
26 0 78.23 13 48 254 40301 1996
41 0 17.83 26 41 98 20501 1996
42 0 92.02 12 75 7 20502 1996};
c3 = [A{:,3}]';
p5 = prctile(c3,5);
bot = c3 <= p5;
A = [A,num2cell(bot)];
0 件のコメント
Guillaume
2014 年 8 月 17 日
sortedcolumn = sort([A{:, 3}]);
index = floor(0.05 * numel(sortedcolumn)); %could use round as well
threshold = sortedcolumn(index);
Gets you the max of your 5 percentile.
inbottom = num2cell(A{:, 3} < threshold); tells which rows is in bottom percentile
[A{:, 9}] = inbottom{:}; %puts it in new 9th columnn
To insert in new column.
Note, this uses expansion of cell arrays to comma-separated lists. Search for comma-separated list in the matlab doc for more information.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Descriptive Statistics についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!