📄 xstat.m
字号:
% xstat.m
% Scope: This MATLAB program tests the following macros: rms, rss, rssxy,
% and statup. In addition, results from internal macros mean and std
% are recorded.
% Usage: xstat
% Inputs: - name of the input data file containing at least 3 columns
% - name of the output file if selected, otherwise the data are
% displayed on screen
% Outputs: - input/output data stored on the selected output file or
% displayed on the screen
% External Matlab macros used: rms, rss, rssxy, statup.
% Last update: 04/19/00
% Copyright (C) 1996-00 by LL Consulting. All Rights Reserved.
clear
% Enter the input data
disp(' ');
fname = input('Specify the name of the input data file --> ','s');
disp(' ');
tt = load(fname);
[nrow,ncol] = size(tt);
if ncol < 3
error('XSTAT - Error : check the input data (less than 3 columns)');
end
x = tt(1:nrow,1);
xy = tt(1:nrow,1:2);
xyz = tt(1:nrow,1:3);
% Determine the mean value for the array x
xmean = mean(x);
% Determine the standard deviation value for the array x
xstd = std(x);
% Determine the rms value for the array x
xrms = rms(x);
% Determine the rss value for the arrays x and y
xrssxy = rssxy(xy);
% Determine the rss value for the arrays x, y and z
xrss = rss(xyz);
% Determine the running mean (am), standard deviation (astd) and root mean
% squares (arms) values for the array x
np1 = 1;
am = 0.;
astd = 0.;
arms = 0.;
for k = 1:nrow
xnp1 = x(k);
[np1,am,astd,arms] = statup(np1,xnp1,am,astd,arms);
end
% Save computed results into an external file if selected
yes = 'y';
answer = input('Do you want to save the results? (y/n)[n] --> ','s');
if (strcmp(answer,yes) == 1)
disp(' ');
f2 = input('Specify the output filename --> ','s');
disp(' ');
else
f2 = 1; % output to the screen
end
fprintf(f2,'\n ***** Results for the first column of the input data \n');
fprintf(f2,' by using the macros: mean, std, rms, statup (for \n');
fprintf(f2,' running values) \n\n');
fprintf(f2,'mean(x) = %15.7f\n',xmean);
fprintf(f2,'std(x) = %15.7f\n',xstd);
fprintf(f2,'rms(x) = %15.7f\n',xrms);
fprintf(f2,'running mean(x) = %15.7f\n',am);
fprintf(f2,'running std(x) = %15.7f\n',astd);
fprintf(f2,'running rms(x) = %15.7f\n\n\n',arms);
fprintf(f2,' ***** Results for the first two columns of the input data\n');
fprintf(f2,' by using the macro rssxy \n\n');
for k = 1:nrow
fprintf(f2,'%16.7f \n',xrssxy(k));
end
fprintf(f2,'\n ***** Results for the first three columns of the input data\n');
fprintf(f2,' by using the macro rss \n\n');
for k = 1:nrow
fprintf(f2,'%16.7f \n',xrss(k));
end
disp(' ');
disp('End of the program XSTAT');
disp(' ');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -