Matlab中自定义函数Percentile2i分享

[Matlab中自定义函数Percentile2i分享
亲测没有问题

function I=percentile2i(h,P)
%PERCENTILE2I Computes an intensity value given a percentile.
%I=PERCENTILE2I(H,P) Given a percentile,P,and a histogram,
%H,this function computes an intensity,I,representing the
%Pth percentile and returns the value in I.P must be in the
%range [0, 1] and I is returned as a value in the range [0, 1]
%also.

%Check value of P.
if P<0||P>1
erro(‘The percentile must be in the range [0, 1]’)
end
%Normalized the histogram to unit area.If it is already normalized
%the following computation has no effect.
h=h/sum(h);
%Cummulative distribution.
C=cumsum(h);
%Calculations.
idx=find(C>=P,1,‘first’);
%Subtract 1 from idx because indexing starts at 1,but intensities
%start at 0.Also,normalize to the range [0, 1].
I=(idx-1)/(numel(h)-1);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值