function x = spm_invNcdf(F,u,v) % Inverse Cumulative Distribution Function (CDF) for univariate Normal % FORMAT x = spm_invNcdf(F,u,v) % % F - CDF (lower tail p-value) % u - mean [Defaults to 0] % v - variance (v>0) [Defaults to 1] % x - ordinates of N(u,v) at which CDF F(x)=F %__________________________________________________________________________ % % spm_invNcdf implements the inverse of the Cumulative Distribution % Function (CDF) for the Normal (Gaussian) family of distributions. % % Returns the variate x, such that Pr{X 1; if sum(xa)>1 && any(any(diff(as(xa,:)),1)) error('Non-scalar arguments must match in size.'); end %-Computation %-------------------------------------------------------------------------- %-Initialise result to zeros x = zeros(rs); %-Only defined for F in [0,1], & strictly positive variance v. % Return NaN if undefined. md = ( F>=0 & F<=1 & ones(size(u)) & v>0 ); if any(~md(:)) x(~md) = NaN; warning('SPM:outOfRangeNormal','Returning NaN for out of range arguments.'); end %-Compute where defined Q = find(md); if isempty(Q), return, end if xa(1), QF=Q; else QF=1; end if xa(2), Qu=Q; else Qu=1; end if xa(3), Qv=Q; else Qv=1; end %-Compute x(Q) = ( -sqrt(2)*erfcinv(2*F(QF)) .* sqrt(v(Qv)) ) + u(Qu);