?? 5-9.m
字號(hào):
%stats_1.m
%purpose: to calculate mean and the standard deviation of
%an input data set containing an arbitrary number
%of input values.
%Define variable
%n --The number of input samples
%std_dev --The standard deviation of the input samples
%sum_x --The sum of the input values
%sum_1x --The sum of the squares of the input values
%x --An input data value
%xbar --The average of the input samples
%Initialize sums.
n=0;sum_x=0;sum_x1=0;
x=input('Enter first value:');
while x>=0
n=n+1;
sum_x=sum_x+x;
sum_x1=sum_x1+x^2;
x=input('Enter next value:');
end
%calculate the mean and standard deviation
x_bar=sum_x/n;
std_dev=sqrt((n*sum_x1-sum_x^2)/(n*(n-1)));
fprintf('The mean of this data set is :%f\n',x_bar);
fprintf('The standard deviation is :%f\n',std_dev);
fprintf('The number of data points is :%f\n',n);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -