r - 请将此位错误概率的R代码转换为matlab
问题描述
prob=function(E,m) #--- prob is the estimated error probabity for given values of signal to
#---noise ratio E and sample size m
{
stopifnot(E>=0 & m>0) #--- this says that the function won't accept negative values of E and
#---m shoulde be at least 1
n=rnorm(m) #--- this says that n is a random sample of size m from N(0,1)
#---distribution
m=mean(n< -sqrt(E)) #--- this says that m is the proportion of values in n which are less
#---than the negative root of E
return(m) #--- this gives us the value of m, which is the estimated error
#---probability
}
E=seq(0,2,by=0.001)
sam=1000
y=sapply(E,prob,m=sam)
p=10*log10(E)
plot(p, log(y),
main="Graph For The Error Probabilities",
xlab=expression(10*log[10](E)),
ylab="log(Error Probability)",
type="l")
解决方案
你可以试试下面的 MATLAB 代码
clc;
clear;
close all;
function y = prob(E,m)
assert(E>=0 & m>0);
n = randn(1,m);
y = mean(n+sqrt(E)<0);
end
E = 0:0.001:2;
sam = 1000;
y = arrayfun(@(x) prob(x,sam),E);
p = 10*log10(E);
plot(p,log(y));
title("Graph For The Error Probabilities");
xlabel('10\log_{10}(E)');
ylabel("log(Error Probability)");
推荐阅读
- validation - Graphql 输入强制属性
- android - 使用 FloatingSearchView android 在操作菜单栏上显示徽章
- c++ - 使用 istream 重载覆盖类对象
- php - PHPMAiler DKIM 签名在命令行中工作(但不在浏览器中)
- r - 如何从最初不可见的动态生成的 UI 元素中访问值
- python - 有没有更好的读取文件的方法?
- pandas - 替换 DataFrame 中的 NaN 值
- angular - Angular LocalStorage Service setter 和 getter 不被识别为函数
- security - 如何存储用于在不同平台上进行身份验证的密码?
- excel - 运行时错误 91 将数据复制到工作簿并通过电子邮件发送