⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 error_message.m

📁 matlab宝典,电子工业出版社,包含该书的源码4-6章
💻 M
字号:
% Script file error_message.m
%
% Purpose:
%   To calculate mean and the standard deviation of
%  an input data set containing and arbitrary number
%  of input values.
%
% Define variables:
%  n       The number of input samples
% std_dev   The standard devation of the input samples
% sum1     The sum of the input values
% sum2     The sum of the squares of the input values
% x        input data value
% xvar     The average of the input samples

% Initalize variables
sum1=0;sum2=0;

% Get the number of points to input
n=input('Enter the number of points: ');

% Check to see if we have enough input data.
if n<2
    warning('Not enough input data');
else
    % construct if loop
    for ii=1:n
        x=input('Enter value: ');
        sum1=sum1+x;
        sum2=sum2+x^2;
     end

%Calculate the mean and standard deviation
xvar=sum1/n;
std_dev=sqrt((n*sum2-sum1^2)/(n*(n-1)));

%Print the result
fprintf('The mean of this data set is: %f\n',xvar);
fprintf('The standard deviation is: %f\n',std_dev);
fprintf('The number of data is: %d\n',n);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -