📄 data_outliers3.m
字号:
% %
% %
% % ********************************************************************
% %
% %
% % data_outliers is written by Edward L. Zechmann
% %
% % created 16 December 2007
% %
% % modified 20 December 2007 Added comments.
% % Added col_name field.
% % Improved ability to input data sets
% % of cell arrays.
% % Improved formatiting of output
% % text file.
% %
% % modified 6 January 2007 Added features abs_rta, abs_other, sod
% % and updated comments.
% %
% % modified 26 February 2007 Updated the row units and the array
% % units.
% % Replaced geomean with LMSloc robust
% % mean.
% % Modified code to print actual values
% % including negative numbers, when
% % the absolute value is used to process
% % the descriptive statistics (mean, std,...).
% %
% % modified 19 September 2008 Updated Comments
% %
% % modified 16 December 2008 Added Arithmetic Mean.
% %
% % modified 9 January 2009 Added Default values.
% % Added rounding the output.
% % Added Analysis of Outliers.
% %
% % modified 10 January 2009 Finished updates.
% % modified 11 January 2009 Updated Comments
% %
% % ********************************************************************
% %
% % Please feel free to modify this code.
% %
% % See Also: LMSloc, mean, std, t_confidence_interval
% %
% initialize abs_rta if empty
if nargin < 1 || isempty(abs_rta)
abs_rta=0;
end
num_vars=length(varargin);
if nargin < 2 || isempty(dep_var) || ~isnumeric(dep_var)
dep_var=1;
end
if ~isequal(dep_var, 1)
dep_var=0;
end
if nargin < 3 || isempty(round_kind) || ~isnumeric(round_kind)
round_kind=ones(1+num_vars, 1);
end
if length(round_kind) < (num_vars+1)
for e1=(length(round_kind)+1):(num_vars+1);
round_kind(e1)=0;
end
end
if nargin < 4 || isempty(round_digits) || ~isnumeric(round_digits)
round_digits=ones(1+num_vars, 1);
end
if length(round_digits) < (num_vars+1)
for e1=(length(round_digits)+1):(num_vars+1);
if isequal(round_kind(e1), 1)
round_digits(e1)=3;
else
round_digits(e1)=0;
end
end
end
if nargin < 5 || isempty(abs_rta) || ~isnumeric(abs_rta)
abs_rta=0;
end
if nargin < 6 || isempty(abs_other) || ~isnumeric(abs_other)
abs_other=zeros(1+num_vars, 1);
end
% initialize abs_rta if shorter than varargin
if length(abs_other) < num_vars
for e1=(length(abs_other)+1):num_vars;
abs_other(e1)=0;
end
end
if nargin < 7 || isempty(sod) || ~isnumeric(sod)
sod=1;
end
% Value must be a scalar
sod=sod(1);
if ~isequal(sod, 1);
sod=0;
end
if nargin < 8 || isempty(num_std) || ~isnumeric(num_std)
num_std=2;
end
if nargin < 9 || isempty(outfile) || (~ischar(outfile) && ~isnumeric(outfile))
outfile='outliers_stats';
end
if nargin < 10 || isempty(save_file) || ~isnumeric(save_file)
save_file=1;
end
if nargin < 11 || isempty(row_names)
row_names='';
end
if nargin < 12 || isempty(row_unit)
row_unit='';
end
if nargin < 13 || isempty(col_name)
col_name='';
end
if nargin < 14 || isempty(array_names)
array_names='';
end
if nargin < 15 || isempty(array_units)
array_units='';
end
rta2=rta;
% For analyzing impulsive noise data
% num_data_rows would be the nnumber of frequency bands
% num_cols would be the number of microphone channels
[num_data_rows, buf]=size(rta);
% calculate the maximum number of columns
max_num_cols=1;
for e1=1:num_data_rows;
if iscell(rta)
max_num_cols=max(max_num_cols, length(rta{e1, :}));
else
max_num_cols=max(max_num_cols, length(rta(e1, :)));
end
end
% initialize row_names if shorter than num_data_rows
if length(row_names) < num_data_rows
if iscell(row_names)
% If it is not a string assume it is an array of numbers
if ischar(row_names{1})
for e1=(length(row_names)+1):num_data_rows;
row_names{e1}='';
end
else
for e1=(length(row_names)+1):num_data_rows;
row_names{e1}=0;
end
end
else
if ischar(row_names(1)) && ~isempty(row_names)
buf=row_names;
row_names=cell(num_data_rows);
for e1=1:num_data_rows;
row_names{e1}=[buf, ' ', num2str(e1)];
end
else
for e1=(length(row_names)+1):num_data_rows;
row_names(e1)=0;
end
end
end
end
% initialize row_unit if shorter than num_data_rows
if length(row_unit) < num_data_rows
if iscell(row_unit)
% If it is not a string assume it is an array of numbers
if ischar(row_unit{1})
for e1=(length(row_unit)+1):num_data_rows;
row_unit{e1}='';
end
else
for e1=(length(row_unit)+1):num_data_rows;
row_unit{e1}=0;
end
end
else
if ~isempty(row_unit) && ischar(row_unit(1)) && ~isempty(row_unit)
buf=row_unit;
row_unit=cell(num_data_rows);
for e1=1:num_data_rows;
row_unit{e1}=[buf];
end
else
for e1=(length(row_unit)+1):num_data_rows;
row_unit(e1)=0;
end
end
end
end
% initialize col_name if shorter than max_num_cols
% if length(col_name) < max_num_cols
% if iscell(col_name)
% % If it is not a string assume it is an array of numbers
% if ischar(col_name{1})
% for e1=(length(col_name)+1):max_num_cols;
% col_name{e1}='';
% end
% else
% for e1=(length(col_name)+1):max_num_cols;
% col_name{e1}=0;
% end
% end
% else
% if ischar(col_name(1)) && ~isempty(col_name)
% buf=col_name;
% col_name=cell(max_num_cols, 1);
% for e1=1:max_num_cols;
% col_name{e1}=[buf, ' ', num2str(e1)];
% end
% else
% for e1=(length(col_name)+1):max_num_cols;
% col_name(e1)=0;
% end
% end
% end
%end
% col_name must be a string
if iscell(col_name)
% If it is not a string assume it is an array of numbers
if ischar(col_name{1})
col_name=col_name{1};
else
col_name=num2str(col_name{1});
end
else
% If it is not a string assume it is an array of numbers
if ischar(col_name)
% Do nothing
else
col_name=num2str(col_name);
end
end
% initialize array_names if shorter than num_vars=length(varargin)
if length(array_names) < (num_vars+1)
if iscell(array_names)
% If it is not a string assume it is an array of numbers
if ischar(array_names{1})
for e1=(length(array_names)+1):(num_vars+1);
array_names{e1}='';
end
else
for e1=(length(array_names)+1):(num_vars+1);
array_names{e1}=0;
end
end
else
if ischar(array_names(1)) && ~isempty(array_names)
buf=array_names;
array_names=cell((num_vars+1), 1);
for e1=1:(num_vars+1);
array_names{e1}=[buf, ' ', num2str(e1)];
end
else
for e1=(length(array_names)+1):(num_vars+1);
array_names(e1)=0;
end
end
end
end
% initialize array_units if shorter than num_vars=length(varargin)
if length(array_units) < (num_vars+1)
if iscell(array_units)
% If it is not a string assume it is an array of numbers
if ischar(array_units{1})
for e1=(length(array_units)+1):(num_vars+1);
array_units{e1}='';
end
else
for e1=(length(array_units)+1):(num_vars+1);
array_units{e1}=0;
end
end
else
if ischar(array_units(1)) && ~isempty(array_units)
buf=array_units;
array_units=cell((num_vars+1), 1);
for e1=1:(num_vars+1);
array_units{e1}=[buf, ' ', num2str(e1)];
end
else
for e1=(length(array_units)+1):(num_vars+1);
array_units(e1)=0;
end
end
end
end
ptsa=cell(num_data_rows,(num_vars+1));
nptsa=cell(num_data_rows,(num_vars+1));
mn_rt1a=zeros(num_data_rows,1);
mn_rt2a=zeros(num_data_rows,1);
stdrta=zeros(num_data_rows,1);
ci_inta=zeros(num_data_rows,1);
median_indexa=zeros(num_data_rows,1);
median_val=zeros(num_data_rows,1);
min_rta=zeros(num_data_rows,1);
max_rta=zeros(num_data_rows,1);
out_mn_rt1a=zeros(num_data_rows,1);
out_mn_rt2a=zeros(num_data_rows,1);
out_stdrta=zeros(num_data_rows,1);
out_ci_inta=zeros(num_data_rows,1);
out_median_indexa=zeros(num_data_rows,1);
out_median_val=zeros(num_data_rows,1);
out_min_rta=zeros(num_data_rows,1);
out_max_rta=zeros(num_data_rows,1);
% Initialize the maximum number of outliers in array rta data row.
max_num_out=0;
for e1=1:num_data_rows;
if iscell(rta);
buf1=rta{e1, :};
if iscell(buf1);
rt=buf1{1};
else
rt=buf1;
end
else
rt=rta(e1, :);
end
num_cols=length(rt);
if num_cols > 0
if isequal(abs_rta, 1)
rtb=abs(rt);
else
rtb=rt;
end
% Calculate the robust estimate of the mean.
%
% Statistical language for this type of mean is
% "calculates the Least Median of Squares (LMS)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -