How to retrieve the list of numbers from which the average of a normal simulation is derived?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Angelavtc
am 25 Sep. 2021
Kommentiert: Angelavtc
am 26 Sep. 2021
Hello all!
I am currently using the following code to calculate the average of 5000 numbers simulated with a normal distribution with a changing mean and std deviation, from 75 to 125 and 1 to 40, respectively.
n = 5000; %Number of Simulations, sample size
x1 = 75:125; %Mean simulation range
y1 = 1:40; %Standard Deviation range
for i = 1:length(x1) % mean
for j = 1:length(y1) % sd
Exp_Pw(i,j) = mean(0.5*(normrnd(x1(i),y1(j),n,1)));
end
end
The problem is that I don't know precisely the 5000 numbers where the average comes from, and I would like to have that information in maybe a cell array? (if this is the name) that would allow me to use those different simulated numbers in other operations. Any idea how to do it?
Thank you very much!
0 Kommentare
Akzeptierte Antwort
David Hill
am 25 Sep. 2021
n = 5000; %Number of Simulations, sample size
x1 = 75:125; %Mean simulation range
y1 = 1:40; %Standard Deviation range
N=zeros(n,length(y1),length(x1));
for i = 1:length(x1) % mean
for j = 1:length(y1) % sd
N(:,i,j)=normrnd(x1(i),y1(j),n,1);%this will contain all values
Exp_Pw(i,j) = mean(0.5*(N(n,i,j)));
end
end
6 Kommentare
Image Analyst
am 26 Sep. 2021
Since you can do
r = normrnd(mu,sigma)
you have r. I think the confusion was when you said you need to "retrieve" or "identify" r, when in fact you already had r.
I think what you really meant was that you wanted to save all the r into an array. And to save them (instead of just generating, using, and then throwing away the numbers inside each iteration, which would be fine by the way), then yes, you'd need a 3-D array to save them. Anyway, thanks for accepting David's answer to award him reputation points.
Weitere Antworten (1)
Image Analyst
am 25 Sep. 2021
I'm not sure what you're asking. If all you have is a mean, say 75, then there are an infinite number of data values that could have gone into getting that mean of 75. You can't know them if all you have is the mean and standard deviation, though you could create some similar ones with randn().
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!