Borrar filtros
Borrar filtros

Why am I getting an array of NaN when using icdf?

7 visualizaciones (últimos 30 días)
Brigitta Rongstad
Brigitta Rongstad el 9 de Jun. de 2016
Editada: Walter Roberson el 26 de Oct. de 2016
I'm trying to calculate the inverse of the cumulative normal distribution function of a set of random numbers. No matter what I do, I end up with an array of NaN. I'm pretty sure this has to do with how I've set up my random numbers, but I'm not clear on how to fix it. An example of my code is below. Thanks!
mu = 28;
sigma = 2;
P = normrnd(mu,sigma,350,1);
X = icdf('Normal',P,mu,sigma);

Respuesta aceptada

Roger Stafford
Roger Stafford el 10 de Jun. de 2016
Editada: Walter Roberson el 26 de Oct. de 2016
The ‘icdf’ function computes the inverse of a cdf function, which means that it receives a probability value or values and obtains the corresponding random value(s) in the indicated cumulative distribution. In your case you used values from ‘normrnd’ as the second argument instead of probability values. That is a mistake. Whenever your P values fall outside the range [0,1] as they are bound to do, you will get a NaN as a consequence. You need to rethink what you are trying to do. Look up the site:
and see what it really says.
Your statement "calculate the inverse of the cumulative normal distribution function of a set of random numbers" indicates a misunderstanding. To get the inverse of a cumulative distribution function you don't start with random number values, you start with cumulative probability values and obtain corresponding random variable ranges, and of course those probability values must always lie between zero and one.
  2 comentarios
Brigitta Rongstad
Brigitta Rongstad el 10 de Jun. de 2016
I had already read the help page, but thank you. I figured it out after using a new function.
Kristina Bevec Mohl
Kristina Bevec Mohl el 25 de Oct. de 2016
What function did you use? I have the same problem and don't know how to fix it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by