How to generate normal distribution from an array?
32 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
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.
To read more about the "fitdist()" function, you can refer the following link:
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)
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)
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!