Hello,
How to i create a nxn matrix where each column represents a normal distribution and the values in each colum sum to 100? Thankyou

 Réponse acceptée

Jeff Miller
Jeff Miller le 23 Juil 2020

1 vote

n = 8; % whatever n you want
sd = 1; % whatever you want for the standard deviation of the normal distribution in each column
total = 100; % the total you want
x = randn(n,n) * sd;
for i=1:n
x(:,i) = x(:,i) - mean(x(:,i)) + total/n;
end

5 commentaires

Chantal Lewis
Chantal Lewis le 23 Juil 2020
Great, thanks
Karlyn Jones
Karlyn Jones le 30 Juil 2020
Hello Jeff, can this also be used z-table's for which the values go above 4? The z table I am using only goes up till 4 and I'm trying solve a problem which lies outside of that value and I'm struggling to find a z table chart which is similar online. Can the code you mentioned be used to generate z table values beyond 4?
Jeff Miller
Jeff Miller le 30 Juil 2020
Sorry, I don't understand how your query relates to this code. Maybe you should open a new question and give more information about what you are trying to do.
Bruno Luong
Bruno Luong le 30 Juil 2020
Modifié(e) : Bruno Luong le 30 Juil 2020
Those ztable is known as https://en.wikipedia.org/wiki/Normal_distribution#Cumulative_distribution_function can computed in MATLAB as following
ztab = @(z) (erf(z/sqrt(2))+1)/2;
z = (-1:0.1:1)'; % put here whatever the z values you want to compute
zt = ztab(z);
table(z,zt)
It produces this
z zt
____ _______
-1 0.15866
-0.9 0.18406
-0.8 0.21186
-0.7 0.24196
-0.6 0.27425
-0.5 0.30854
-0.4 0.34458
-0.3 0.38209
-0.2 0.42074
-0.1 0.46017
0 0.5
0.1 0.53983
0.2 0.57926
0.3 0.61791
0.4 0.65542
0.5 0.69146
0.6 0.72575
0.7 0.75804
0.8 0.78814
0.9 0.81594
1 0.84134
And here the value of ztab of 4 and 5
>> fprintf('z(4)=%1.16f\n', ztab(4))
z(4)=0.9999683287581669
>> fprintf('z(5)=%1.16f\n', ztab(5))
z(5)=0.9999997133484282
Karlyn Jones
Karlyn Jones le 31 Juil 2020
@bruno luong Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by