matlab 样本均值,Matlab | Matlab从入门到放弃(4)——样本均值

Matlab | Matlab从入门到放弃(4)——样本均值

Matlab | Matlab从入门到放弃(4)——样本均值

博主github:https://github.com/MichaelBeechan

博主CSDN:https://blog.csdn.net/u011344545

代码下载:https://github.com/MichaelBeechan/Matlab-From-Zero-To-One

%% Time:2019.5.25

%% Function:edit learning4

% Generate random data from a uniform distribution

% and calculate the mean. Plot the data and the mean.

n = 50;

r = rand(n, 1);

plot(r)

% Draw a line from (0,m) to (n,m)

m = mean(r);

hold on

plot([0, n], [m, m])

hold off

title('Mean of Random Uniform Data')

%% 使用 for 循环来计算 5 个随机样本的均值和总均值。

nsamples = 5;

npoints = 50;

%{

for k = 1 : nsamples

currentData = rand(npoints, 1);

sampleMean(k) = mean(currentData)

end

overallMean = mean(sampleMean)

%}

for k = 1:nsamples

iterationString = ['Iteration #',int2str(k)];

disp(iterationString)

currentData = rand(npoints,1);

sampleMean(k) = mean(currentData)

end

overallMean = mean(sampleMean)

if overallMean < .49

disp('Mean is less than expected')

elseif overallMean > .51

disp('Mean is greater than expected')

else

disp('Mean is within the expected range')

end

8dddfdda3c5089d0821cdfffeeb6ba04.png

Matlab | Matlab从入门到放弃(4)——样本均值相关教程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值