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

MATLABpercentage

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.

Best Answer

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: