use the error function in matlab

The error function, also known as the Gauss error function, is widely used in mathematics, statistics, and engineering. In MATLAB, the error function is implemented as a built-in function erf(x).

To use the error function in MATLAB, simply pass a numeric scalar, vector, or matrix as the argument to erf().

main.m
x = 2.5;
y = erf(x);
disp(y) % output: 0.999593047981  (approximate)

% using an array
x = [-3 -2 -1 0 1 2 3];
y = erf(x);
disp(y) % output: [-0.99997791 -0.99532227 -0.84270079 0 0.84270079 0.99532227 0.99997791]
214 chars
9 lines

Note that the output of erf() will always be a numeric value between -1 and 1, indicating the probability of a normal distribution.

gistlibby LogSnag