how to find the mean of normally distributed data
2 views (last 30 days)
Show older comments
I want to find the normally distributed data with different sample size and find the mean of it. My code works perfectly fine but I want to know if there is better ways to code such problem, such as finding mean right away without setting it to new variable
Here is my work.
M1= normrnd (80,15,[1 10]); %normal dist, mean 80 std 15 sample 10
M2= normrnd (80,15, [1 20]); %normal dist, mean 80 std 15 sample 20
M3= normrnd (80,15, [1 50]); %normal dist, mean 80 std 15 sample 50
M4= normrnd (80,15, [1 100]); %normal dist, mean 80 std 15 sample 100
M5= normrnd (80,15, [1 200]); %normal dist, mean 80 std 15 sample 200
b1=mean (M1); % find mean of each matrix
b2=mean (M2);
b3=mean (M3);
b4=mean (M4);
b5=mean (M5);
meanM= [10,b1;20,b2;50,b3;100,b4;200,b5]; %matrix of sample size vs mean
disp(' sample size mean of data')
disp(meanM)
0 Comments
Answers (2)
Image Analyst
on 16 Feb 2015
No - it can't get much simpler, though you could do it differently. You're doing it right. There are other ways but for only 5 cases, it doesn't really simplify things any.
0 Comments
Roger Stafford
on 16 Feb 2015
To reduce the number of lines you could do this:
I = [10;20;50;100;200];
CI = [0;cumsum(I)];
CR = cumsum([0;normrnd(80,15,CI(end),1)]);
meanM = [I,(CR(CI(2:end)+1)-CR(CI(1:end-1)+1))./I];
However, as Image Analyst indicates, for only five cases it may not be worth the extra effort in thinking it out.
0 Comments
See Also
Categories
Find more on Computational Geometry in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!