# How to generate normal distribution from an array?

35 visualizzazioni (ultimi 30 giorni)
William il 6 Lug 2023
A = [2.29441228002842 17.3351873969651 2.79928860040389 7.17554281085515;
3.16200415659481 16.9975006219209 3.18395042061777 7.45747601536461;
4.55387378846938 13.4948344868957 3.22594708715312 7.49001605579868]
B = normrnd(mean(A(:,1),1),std(A(:,1),1),[50,1])
we can get array result for column 1 of A. So, dimension of matrix B is [50,1] of normal distribution.
Actually, I want to expect B dimension is [50,4] using condition of mean and std just like above.
I want to do it without creating another function of normal distribution.Because, It will create another file.m
ex:
B = normrnd(mean(A,1),std(A,1),[50,4])
• The function "normrnd" is not working, error
Thanks
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Naman Kaushik il 6 Lug 2023
Hi William,
I understand that you wish to find the Normal distribution for an array.
One way to do this would be to use the "fitdist()" function. You can pass your array as the input and speicfy that you wish for the normal distribution.
dist = fitdist(data, 'Normal');
Here, you data would be a column vector which you can make by simply taking the transpose of your array.
The output that you get would be a struct with the information that would be relevant to you.
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
William il 6 Lug 2023
Yeah.. But, I want a constrained normal distribution with using spesific mean and std.

Accedi per commentare.

Nathan Hardenberg il 6 Lug 2023
You could do it in a small for loop:
A = [2.29441228002842 17.3351873969651 2.79928860040389 7.17554281085515;
3.16200415659481 16.9975006219209 3.18395042061777 7.45747601536461;
4.55387378846938 13.4948344868957 3.22594708715312 7.49001605579868];
B = zeros(50,4); % initialize B
for i = 1:4
B(:,i) = normrnd(mean(A(:,i)), std(A(:,i)), [50,1]); % write to each colum
end
display(B)
B = 50×4
2.9994 17.1683 3.0698 7.1923 3.4782 14.2413 3.4590 7.1612 4.8152 18.2626 3.0337 7.4850 3.1296 17.4887 2.9768 7.3988 3.3263 16.3220 3.1835 7.4234 3.5581 12.1935 2.5272 7.4972 2.6692 12.8850 3.3725 7.1382 4.7436 17.3658 3.1075 7.6050 4.2367 16.2350 3.5494 7.2822 5.4219 17.1790 2.9396 7.3607
Taking @Naman Kaushiks answer into accout, you could also use the fitdist()-function to get the mean and std-deviation.
for i = 1:4
pd = fitdist(A(:,i), 'Normal');
B(:,i) = normrnd(pd.mu, pd.sigma, [50,1]); % write to each colum
end
display(B)
B = 50×4
4.2886 15.4471 3.2503 7.2869 3.8850 12.7500 2.9612 7.2627 2.3870 16.7963 3.1437 7.2130 2.6593 15.2580 3.4847 7.3102 3.4409 14.1389 3.3418 7.6398 3.4434 15.9600 3.1699 7.3803 -1.0641 14.8131 3.0205 7.3550 1.0493 15.6728 3.0498 7.0878 4.4023 16.5267 3.3049 7.5497 3.4593 17.5877 2.6437 7.4040
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Half-Normal Distribution in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by