How can i convert this R code into MATLAB

1 visualización (últimos 30 días)
redman
redman el 6 de Mzo. de 2021
Comentada: Walter Roberson el 6 de Mzo. de 2021
The code is as follows
ef=function(x)
{
r=rnorm(10000,0,1/sqrt(2))
v=ifelse(r<=x & r>=0,1,0)
e=2*(sum(v)/length(r))
return(e)
}

Respuestas (1)

Basil C.
Basil C. el 6 de Mzo. de 2021
The rnorm function can be replaced by
r = normrnd(0,1/sqrt(2),[1,1000])
You can read more about it: normrnd
If else statement should be much of a problem if you know the basics of Matlab
  1 comentario
Walter Roberson
Walter Roberson el 6 de Mzo. de 2021
r = normrnd(0,1/sqrt(2),[1,1000])
e = 2 * mean(r>=0 & r<=x);
The code expects scalar x.
It seems a bit odd to simulate it instead of calculating normcdf()

Iniciar sesión para comentar.

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by