randi generate a normally distributed integer matrix

I encountered a problem while studying the courses officially provided by matlab. The question requires using the randi function to generate a normally distributed rather than uniformly distributed integer matrix. After consulting the help file of the randi function, I did not find this function.

댓글 수: 4

Could you share in which section of which course you see that instruction?
It sounds like a mistake, normal distribution is continuous distribution, not discrete. So either RANDI or NORMAl stated in the course is incorrect.
You might have misread it as integers rather than numbers.
There is a function that generates normally distributed random numbers i.e. randn.
However, this is only a guess. For a definite feedback, please provide the information @Steven has asked in the comment above.
John D'Errico
John D'Errico 2023년 10월 26일
편집: John D'Errico 2023년 10월 26일
Can you use randi to generate a normally distributed matrix? Of course not. You may be mistaken. Or the person writing the question may have not understood what they are asking. After all, people are only human. Even those who write questions as part of courses or textbooks, even teachers.
You could use randi as part of something to generate a sample that will APPROXIMATE a normal distribution, with some effort. I can think of several ways to do that.
If you can show/quote the actual quetion, we might be able to help you. But doing what you seem to think you want to do is not possible.

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

답변 (1개)

The following illustrates that it is possible to create an array of integers whos population statistics approximate normal distribution. The larger the population generated, the more the array (here called discrete) would approximate normal distribution.
This does not show you anything about how to create such a distribution starting with randi() -- just that there are meaningful senses in which it could exist.
rng('shuffle')
N = 1000;
continuous = randn(N,1);
scalefactor = (2^53 - 1);
bins = -1:.1:1;
discrete = round(continuous * scalefactor);
descaled = discrete ./ scalefactor;
sdc = std(continuous)
sdc = 0.9900
sdd = std(descaled)
sdd = 0.9900
sdi = std(discrete)
sdi = 8.9170e+15
r = sdi / sdc
r = 9.0072e+15
scalefactor / r
ans = 1.0000
histogram(continuous, bins)
histogram(descaled, bins)
histogram(continuous - descaled)
histogram(discrete, bins*scalefactor)
[H,P,CI,STATS] = ttest2(continuous, descaled)
H = 0
P = 1
CI = 2×1
-0.0868 0.0868
STATS = struct with fields:
tstat: 0 df: 1998 sd: 0.9900

댓글 수: 2

One could use the well known central limit theorem, no need to mess with number bit coding and poor results.
But that is not the point. It is still not a normal distribution strictly speaking
n=1000000;
ns=100; % larger -> better approximation
r=sum(randi([-1000 1000],ns,n))/(sqrt(sum((-1000:1000).^2)*ns/(2001)));
histogram(r,'Normalization','pdf');
x=linspace(-3,3);
hold on
plot(x,1/sqrt(2*pi)*exp(-x.^2/2),'g','linewidth',2)
Any finite sampling of normally distribute samples will not be normally distributed "strictly speaking".

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

태그

질문:

Lzy
2023년 10월 25일

댓글:

2023년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by