# # function [fp,pc,ac,np] = percent(f) # # Compute percentages and cumulative percentages from a vector f. # We assume that f (usually the output of eig+sort) contains a # decreasing sequence of positive numbers and possibly one or more # zeros. Negative entries are discarded. # # Input: # f (a row vector) # # Output: # # fp = the first part of f, containing only positive entries. # pc = row vector containing percentages (of each entry in # f with respect to the sum of all (positive) entries). # ac = row vector containing cumulative percentages # np = number of positive entries in f (equal to the length # of fp, pc and ac) # function [fp,pc,ac,np] = percent(f) eps1=1.e-9; [m,n]=size(f); ac=zeros(1,n); t=0;np=n; for ni=1:n if f(ni)>eps1 t=t+f(ni); ac(ni)=t; else np=ni-1; break; endif endfor fp=f(1:np); pc=fp*100/t; ac=ac(1:np)*100/t; disp(["*** percent: Found " num2str(n-np) " nonpositive elements"]); endfunction