📄 5-9.m
字号:
%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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -