Less than what number in the file ht could give 95%?

4 ビュー (過去 30 日間)
AbelM Kusemererwa
AbelM Kusemererwa 2015 年 7 月 7 日
コメント済み: Star Strider 2015 年 7 月 8 日
Attached is column vector ht . I would want to find out below what number in ht would constitute 95% of ht ? For example, numbers in ht that are less than 25 constitute 43.78% of ht.

採用された回答

Star Strider
Star Strider 2015 年 7 月 7 日
It took me a bit to understand what you wanted, but the result is actually straightforward:
D = load('ht.mat');
ht = D.ans;
ht95idx = fix(0.95*length(ht));
ht95 = ht(ht95idx)
figure(1)
plot(ht, '-r')
hold on
plot(ht95idx, ht95, 'bp')
hold off
grid
xlabel('index')
ylabel('ht')
text(ht95idx-150, ht95, sprintf('95%%‘ht’ at %5.1f \\rightarrow', ht95), 'HorizontalAlignment','right')
The plot of ‘ht’ as a function of its index:
  10 件のコメント
AbelM Kusemererwa
AbelM Kusemererwa 2015 年 7 月 8 日
Thanks
Star Strider
Star Strider 2015 年 7 月 8 日
My pleasure!

サインインしてコメントする。

その他の回答 (2 件)

bio lim
bio lim 2015 年 7 月 7 日
編集済み: bio lim 2015 年 7 月 7 日
First of all, I think it is bad idea to save your variable as ' ans ', so you should define a unique name. (I have renamed ' ans ' to ' data ' in your ht.mat file.)
This might be a clumsy code but should do the trick.
load('ht.mat')
x = zeros(size(data)); % Create vector of zeros
for i = 1 : length(data)
x(i) = sum(data==data(i)); % Counting the number of occurance
end
z = [data x]; % Matrix with first column as your initial data, and second as the number of occurence.
h = unique(z, 'rows'); % Only unique elements are selected.
sum = cumsum(h(:,2)); % 95% of 23880 is 22686
g = [h sum];
Thus less than 34.7 could give you 95% (More precisely 95.017%) . Hope it helps.

Sean de Wolski
Sean de Wolski 2015 年 7 月 7 日
編集済み: Sean de Wolski 2015 年 7 月 7 日
You should be able to use prctile for this.
x = rand(100,1);
xp = prctile(x,[0,95]); % 2nd element
plot(sort(x))
line([1 100],xp([2 2]))
title(['95% is ' num2str(xp(2))])

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by