function np=sample(pdf, rangelow, rangehigh, dx) % sample(pdf, rangelow, rangehigh, samples) Helper function for convpf. % Generates a row vector with the given sample spacing dx, sampled from % the p values of pdf over the given range if ispf(pdf)==0 | isdiscrt(pdf)==1 error('invalid pdf') end if rangelow>rangehigh error('invalid range') end x=xvals(pdf); TR=rangehigh-rangelow; R=max(x)-x(1); np=zeros(1, round(TR/dx-0.5)); p=pvals(pdf); X=rangelow; i=1; while X<=rangehigh, if Xmax(x) np(i)=0; else index=round(((X-x(1))/R)*length(x)); if index==0 index=1; end np(i)=p(index); end X=X+dx; i=i+1; end