Why are my Gaussian distributions not properly being generated?

1 次查看(过去 30 天)
N1 = 1e4;
Y1 = randn(N1,-5,4);
%
N2 = 1e4;
Y2 = randn(N2,5,3);
N3 = 1e4;
Y3 = randn(N3,0,5);
figure(5); clf
histogram(Y3,'Normalization','pdf');
hold on;
%plot(0:Y3-1,1/Y3*ones(size(1:Y3)),'r','LineWidth',2), could not get this
hold off
xlabel('random variable $x$','Interpreter','latex','FontSize',20)
ylabel('Probability density','Interpreter','latex','FontSize',20)
title('Continuous uniform PDF','Interpreter','latex','FontSize',20)
  1 个评论
Kevin Nelson
Kevin Nelson 2022-9-13
I'm supposed to be adding Y1 and Y2 (I was told to add the means (-5 + 5 = 0) and the SD (sqrt(4^2 + 3^2) to get Y3, if that is even right

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2022-9-13
Y1 = randn(N1,-5,4);
The numeric parameters to randn() are all sizes so you asked for an array that is N1 by negative 5 by 4.
I suspect that you want
Y1 = randn(1,N1) * 4 - 5
which is multiply by standard deviation and add the mean.

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by