29 views (last 30 days)

Show older comments

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!

David Hill
on 25 Sep 2021 at 20:09

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

Image Analyst
on 25 Sep 2021 at 21:16

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

Start Hunting!