How can i convert this R code into MATLAB

조회 수: 2 (최근 30일)
redman
redman 2021년 3월 6일
댓글: Walter Roberson 2021년 3월 6일
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)
}

답변 (1개)

Basil C.
Basil C. 2021년 3월 6일
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
Walter Roberson
Walter Roberson 2021년 3월 6일
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()

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Electrical Block Libraries에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by