| make_summary_impls_stats_table(s, stat_to_get, stat_to_get2, fileout, flag, ratio_metrics, round_kind, round_digits)
|
function make_summary_impls_stats_table(s, stat_to_get, stat_to_get2, fileout, flag, ratio_metrics, round_kind, round_digits)
% % make_summary_impls_stats_table: Makes a summary table of the output of the Impulsive_Noise_Meter; Impulse, Impulsive, Noise, Sound, Meter
% %
% % Syntax:
% %
% % make_summary_impls_stats_table(s, stat_to_get, stat_to_get2, fileout, flag, ratio_metrics, round_kind, round_digits);
% %
% % *****************************************************************
% %
% % Description:
% %
% % This program takes the output from the Impulsive_Noise_Meter and
% % calc_channel_diff prorgams and prints a summary of the descriptive
% % statistics of the metrics to a table. Also a summary of the statistics
% % across channels and overall statistic across files is printed.
% %
% % The Table has a format described by the summary pattern below
% %
% % Label stat_to_get(1) (Arithmetic Mean, Robust Mean , etc)
% %
% % Metric 1 Metric 1 ...
% % var 1 var 2 ...var n var 1 var 2 ...var n ...
% % File 1
% % channel 1 d1 d2 dn d1 d2 dn
% % channel ... ...
% % channel m
% %
% % ...
% %
% % File x
% % channel 1 d1 d2 dn d1 d2 dn
% % channel ... ...
% % channel m
% %
% %
% % Summary Across Channels var 1 var 2 ...var n var 1 var 2 ...var n
% % stat_to_get2(1)
% % File 1 d1 d2 dn d1 d2 dn
% % ... ...
% % File x
% %
% % ...
% %
% % stat_to_get2(xx)
% % File 1 d1 d2 dn d1 d2 dn
% % ... ...
% % File x
% %
% %
% % Summary Across Files var 1 var 2 ...var n
% % stat_to_get2(1)
% % File 1 d1 d2 dn d1 d2 dn
% % ... ...
% % File x
% %
% % ...
% %
% % stat_to_get2(xx)
% % File 1 d1 d2 dn d1 d2 dn
% % ... ...
% % File x
% %
% %
% % ...
% %
% %
% % Label stat_to_get(2) (Arithmetic Mean, Robust MEan , etc)
% %
% % Metric 1 Metric 1 ...
% % var 1 var 2 ...var n var 1 var 2 ...var n ...
% % File 1
% % channel 1 d1 d2 dn d1 d2 dn
% % channel ... ...
% % channel m
% %
% % ...
% %
% % File x
% % channel 1 d1 d2 dn d1 d2 dn
% % channel ... ...
% % channel m
% %
% %
% % Summary Across Channels var 1 var 2 ...var n var 1 var 2 ...var n
% % stat_to_get2(1)
% % File 1 d1 d2 dn d1 d2 dn
% % ... ...
% % File x
% %
% % ...
% %
% % stat_to_get2(xx)
% % File 1 d1 d2 dn d1 d2 dn
% % ... ...
% % File x
% %
% %
% % Summary Across Files var 1 var 2 ...var n
% % stat_to_get2(1)
% % File 1 d1 d2 dn d1 d2 dn
% % ... ...
% % File x
% %
% % ...
% %
% % stat_to_get2(xx)
% % File 1 d1 d2 dn d1 d2 dn
% % ... ...
% % File x
% %
% %
% %
% %
% % The input and output variables are described below.
% %
% % *****************************************************************
% %
% % Input Variables
% %
% % s={}; load shock_tube; % is the data structure created using the
% % % Impulsive_Noise_Meter.
% % % default is load shock_tube. Runs a demo table.
% %
% % stat_to_get=1:8; % is a vector or constant stipulating which
% % % descriptive statistics to display in the
% % % table summarizing the metrics across the
% % % impulses in a single file.
% % % default is stat_to_get2=1:8; all statistics
% %
% % Any combination of the following stats can be displayed by placing the
% % index of the stat in the array stat_to_get in any desired order.
% %
% % % stat_to_get=1; % Arithmetic Mean
% % % stat_to_get=2; % Robust Mean
% % % stat_to_get=3; % Standard Deviation
% % % stat_to_get=4; % 95% Confidence Interval
% % % stat_to_get=5; % Median
% % % stat_to_get=6; % Median Index
% % % stat_to_get=7; % Minimum
% % % stat_to_get=8; % Maximum
% %
% % stat_to_get2=1:8; % is a vector or constant stipulating which
% % % descriptive statistics to display in the
% % % table summarizing the metrics across the files.
% % % These are called the overall values.
% % % default is stat_to_get2=1:8; all statistics
% %
% % fileout='Output_file_name.txt';
% % % fileout is the filenmae of the output file.
% % % The extension '.txt' is automatically added.
% %
% % flag=1; print absolute stats only
% % flag=2; print difference stats only
% % flag=3; print both absolute and difference stats
% %
% % % if flag does not equal 1, 2, or 3 then print
% % % both absolute and difference stats.
% %
% % ratio_metrics=[3, 4, 5, 20]; % is an array of indices of metrics for
% % % the diff_chans array that are
% % % calculated as ratios instead of
% % % differences
% %
% % round_kind=1; % Array of values one element for the rta array
% % % and one element for each varargin array
% % % (see example)
% % % 1 round to specified number of significant
% % % digits
% % %
% % % 0 round to specified digits place
% % %
% % % default is round_kind=1;
% %
% % round_digits=3; % Array of values one element for the rta array
% % % and one element for each varargin array
% % % (see example)% Type of rounding depends on round_kind
% % %
% % % if round_kind==1 number of significant digits
% % % if round_kind==0 specified digits place
% % %
% % % default is round_digits=3;
% %
% % *****************************************************************
%
%
% Example='1';
%
% % This is an example using shock tube data! The data compares two
% % data acquisition rates.
%
% % An example which outputs the mean of the metrics.
%
% load shock_tube;
% stat_to_get=1;
% stat_to_get2=1;
% fileout='Compare_data_acquisition_sytems';
% flag=1;
% make_summary_impls_stats_table(s, stat_to_get, stat_to_get2, fileout, flag);
%
%
% % Example='2';
%
% % An example which outputs all of the metrics.
%
% load shock_tube;
% stat_to_get=[1:8]; % return all of the stats, from Arithmetic mean
% % to maximum!
% stat_to_get2=[1:8]; % return all of the stats, from Arithmetic mean
% % to maximum!
%
% fileout='Compare_data_acquisition_sytems2';
% flag=3;
% make_summary_impls_stats_table(s, stat_to_get, stat_to_get2, fileout, flag);
%
%
% % *****************************************************************
% %
% %
% % Subprograms
% %
% %
% %
% % List of Dependent Subprograms for
% % make_summary_impls_stats_table
% %
% % FEX ID# is the File ID on the Matlab Central File Exchange
% %
% %
% % Program Name Author FEX ID#
% % 1) file_extension Edward L. Zechmann
% % 2) genHyper Ben Barrowes 6218
% % 3) LMSloc Alexandros Leontitsis 801
% % 4) m_round Edward L. Zechmann
% % 5) num_impulsive_samples Edward L. Zechmann
% % 6) pow10_round Edward L. Zechmann
% % 7) print_channel_stats Edward L. Zechmann
% % 8) print_overall_stats Edward L. Zechmann
% % 9) sd_round Edward L. Zechmann
% % 10) splat_cell Edward L. Zechmann
% % 11) t_alpha Edward L. Zechmann
% % 12) t_confidence_interval Edward L. Zechmann
% % 13) t_icpbf Edward L. Zechmann
% %
% %
% %
% % *****************************************************************
% %
% % Written by Edward L. Zechmann
% %
% % date 6 August 2008
% %
% % modified 9 August 2008 Vectrorized stat_to_get.
% % Updated comments.
% %
% % modified 10 August 2008 Updated comments.
% %
% % modified 1 September 2008 Added print_channel_stats and
% % print_overall_stats to the program
% % which greatly improved its
% % usefulness.
% %
% % modified 10 September 2008 Updated comments.
% %
% % modified 10 December 2008 Updated comments.
% %
% % modified 7 January 2009 Updated comments.
% %
% % modified 19 January 2009 Updated to include rounding.
% %
% % modified 6 October 2009 Updated comments
% %
% %
% %
% % *****************************************************************
% %
% % Please feel free to modify this code.
% %
% % See Also: Main_Sound, Impulsive_Noise_Meter, Main_sound_and_vibs, Continuous_Sound_and_Vibrations_Analysis
% %
if (nargin < 1 || isempty(s)) || ~iscell(s)
s={};
load shock_tube;
end
if (nargin < 2 || isempty(stat_to_get)) || ~isnumeric(stat_to_get)
stat_to_get=[1:8];
end
if (nargin < 3 || isempty(stat_to_get2)) || ~isnumeric(stat_to_get2)
stat_to_get2=[1:8];
end
if (nargin < 4 || isempty(fileout)) || ~ischar(fileout)
fileout='Output_file_name.txt';
end
if (nargin < 5 || isempty(flag)) || ~isnumeric(flag)
flag=3;
end
if (nargin < 6 || isempty(ratio_metrics)) || ~isnumeric(ratio_metrics)
ratio_metrics=[3, 4, 5];
end
if (nargin < 7 || isempty(round_kind)) || ~isnumeric(round_kind)
round_kind=1;
end
if (nargin < 8 || isempty(round_digits)) || ~isnumeric(round_digits)
round_digits=3;
end
[num_files, num_vars]=size(s);
num_channels_array=zeros(num_files,1);
num_stats=length(stat_to_get);
sum_num_channels_a=zeros(num_files, num_vars);
num_channels_a=zeros(num_files, num_vars);
num_diff_channels_a=zeros(num_files, num_vars);
[num_samples_ca]=num_impulsive_samples(s);
% Determine the size of the concatenated metrics table
for e1=1:num_files; % Data files
num_channels=[];
% Number of Variables (Number of Data Acquisition Systems)
for e3=1:num_vars;
if ~isempty(s{e1,e3})
num_channels=0;
num_stats2=0;
if isfield(s{e1,e3}, 'stats_of_metrics')
[num_metrics, num_channels, num_stats2]=size(s{e1,e3}.stats_of_metrics);
end
num_diff_channels=0;
num_diff_stats2=0;
if isfield(s{e1,e3}, 'diff_stats_of_metrics')
[num_metrics, num_diff_channels, num_diff_stats2]=size(s{e1,e3}.diff_stats_of_metrics);
end
if num_channels >= 1 || logical(num_diff_channels >= 1)
switch flag
case 1
num_channels_a(e1, e3)=num_channels;
num_diff_channels_a(e1, e3)=0;
sum_num_channels_a(e1, e3)=num_channels;
num_channels_array(e1)=max([num_channels, num_channels_array(e1)]);
case 2
num_channels_a(e1, e3)=0;
num_diff_channels_a(e1, e3)=num_diff_channels;
sum_num_channels_a(e1, e3)=num_diff_channels;
num_channels_array(e1)=max([num_diff_channels, num_channels_array(e1)]);
case 3
num_channels_a(e1, e3)=num_channels;
num_diff_channels_a(e1, e3)=num_diff_channels;
sum_num_channels_a(e1, e3)=num_channels+num_diff_channels;
num_channels_array(e1)=max([num_channels+num_diff_channels, num_channels_array(e1)]);
otherwise
num_channels_a(e1, e3)=num_channels;
num_diff_channels_a(e1, e3)=num_diff_channels;
sum_num_channels_a(e1, e3)=num_channels+num_diff_channels;
num_channels_array(e1)=max([num_channels+num_diff_channels, num_channels_array(e1)]);
end
end
end
end
end
num_rows=sum(num_channels_array);
num_columns=num_vars*num_metrics;
bb2=zeros(num_rows, num_columns);
max_channels=max(num_channels_array);
num_rows=sum(num_channels_array)+num_files-1;
num_columns=num_vars*num_metrics+num_metrics-1;
bb=cell(num_rows, num_columns);
% Initialize the concatenated metrics table
column_heading=cell(3, num_columns );
num_row_headings=4;
row_heading=cell(num_rows,num_row_headings);
% Determine the length of the one-dimensional rounding arrays.
num_kinds=length(round_kind);
num_digits=length(round_digits);
% Create the files to save the sound and vibrations data
[fileout_base, ext]=file_extension(fileout);
% Open the output file
fid=fopen([fileout_base '.txt'], 'w');
% Fill in the concatenated metrics table
% Add row headings and column headings
for e8=1:num_stats;
for e1=1:num_files; % Data files
for e3=1:num_vars; % Number of Variables (Number of Data Acquisition Systems)
if ~isempty(s{e1,e3})
num_channels=num_channels_a(e1, e3);
num_diff_channels=num_diff_channels_a(e1, e3);
sum_num_channels=sum_num_channels_a(e1, e3);
if sum_num_channels >= 1
for e2=1:sum_num_channels; % Channels
for e4=1:num_metrics; % Data Metrics
e5=sum(num_channels_array(1:e1))-num_channels_array(e1)+e2;
e6=num_vars*(e4-1)+e3;
switch flag
case 1
if e2 <= num_channels
bb2(e5, e6)=s{e1,e3}.stats_of_metrics(e4, e2, stat_to_get(e8));
end
case 2
if e2 <= num_diff_channels
bb2(e5, e6)=s{e1,e3}.diff_stats_of_metrics(e4, e2, stat_to_get(e8));
end
case 3
if e2 <= num_channels
bb2(e5, e6)=s{e1,e3}.stats_of_metrics(e4, e2, stat_to_get(e8));
elseif e2-num_channels <= num_diff_channels
bb2(e5, e6)=s{e1,e3}.diff_stats_of_metrics(e4, e2-num_channels, stat_to_get(e8));
end
otherwise
if e2 <= num_channels
bb2(e5, e6)=s{e1,e3}.stats_of_metrics(e4, e2, stat_to_get(e8));
elseif e2-num_channels <= num_diff_channels
bb2(e5, e6)=s{e1,e3}.diff_stats_of_metrics(e4, e2-num_channels, stat_to_get(e8));
end
end
e5=e1-1+sum(num_channels_array(1:e1))-num_channels_array(e1)+e2;
e6=(num_vars+1)*(e4-1)+e3;
if num_kinds >= e4 && logical(num_digits >= e4)
rk=round_kind(e4);
rd=round_digits(e4);
else
rk=1;
rd=3;
end
% Round the standard deviation and confidence
% interval to 3 significant digits
if ismember(stat_to_get(e8), [3, 4]);
rk=1;
rd=3;
end
switch flag
case 1
if e2 <= num_channels
[bufn, buf_str]=m_round(s{e1,e3}.stats_of_metrics(e4, e2, stat_to_get(e8)), rk, rd);
bb{e5, e6}=buf_str{1};
end
case 2
if ismember(e4, ratio_metrics);
rk=1;
rd=3;
end
if e2 <= num_diff_channels
[bufn, buf_str]=m_round(s{e1,e3}.diff_stats_of_metrics(e4, e2, stat_to_get(e8)), rk, rd);
bb{e5, e6}=buf_str{1};
end
case 3
if e2 <= num_channels
[bufn, buf_str]=m_round(s{e1,e3}.stats_of_metrics(e4, e2, stat_to_get(e8)), rk, rd);
bb{e5, e6}=buf_str{1};
elseif e2-num_channels <= num_diff_channels
if ismember(e4, ratio_metrics);
rk=1;
rd=3;
end
[bufn, buf_str]=m_round(s{e1,e3}.diff_stats_of_metrics(e4, e2-num_channels, stat_to_get(e8)), rk, rd);
bb{e5, e6}=buf_str{1};
end
otherwise
if e2 <= num_channels
[bufn, buf_str]=m_round(s{e1,e3}.stats_of_metrics(e4, e2, stat_to_get(e8)), rk, rd);
bb{e5, e6}=buf_str{1};
elseif e2-num_channels <= num_diff_channels
if ismember(e4, ratio_metrics);
rk=1;
rd=3;
end
[bufn, buf_str]=m_round(s{e1,e3}.diff_stats_of_metrics(e4, e2-num_channels, stat_to_get(e8)), rk, rd);
bb{e5, e6}=buf_str{1};
end
end
if e5 == 1
if e3==1
column_heading{1, e6}=s{e1,e3}.metrics_description{1,e4};
if ismember(e4, ratio_metrics)
column_heading{2, e6}=[s{e1,e3}.metrics_description{2,e4}, '/ratio'];
else
column_heading{2, e6}=s{e1,e3}.metrics_description{2,e4};
end
end
column_heading{3, e6}=['var ' num2str(e3)];
end
if e6 == 1
if e2 == 1
row_heading{e5, 1}=s{e1,e3}.filename;
end
end
if e4 == 1 && isequal(e3, 1)
switch flag
case 1
if e2 <= num_channels
row_heading{e5, 3}=['Channel ' num2str(e2)];
end
case 2
if e2 <= num_diff_channels
row_heading{e5, 3}=['Diff Channel ' num2str(s{e1,e3}.diff_chan(2*e2-1)), ' - ', num2str(s{e1,e3}.diff_chan(2*e2))];
end
case 3
if e2 <= num_channels
row_heading{e5, 3}=['Channel ' num2str(e2)];
elseif e2-num_channels <= num_diff_channels
row_heading{e5, 3}=['Diff Channel ' num2str(s{e1,e3}.diff_chan(2*(e2-num_channels)-1)), ' - ', num2str(s{e1,e3}.diff_chan(2*(e2-num_channels)))];
end
otherwise
if e2 <= num_channels
row_heading{e5, 3}=['Channel ' num2str(e2)];
elseif e2-num_channels <= num_diff_channels
row_heading{e5, 3}=['Diff Channel ' num2str(s{e1,e3}.diff_chan(2*(e2-num_channels)-1)), ' - ', num2str(s{e1,e3}.diff_chan(2*(e2-num_channels)))];
end
end
end
end
end
end
end
end
end
% Concatenate the row_heading, column heading, and data text strings
bb_table=cell(num_rows+3, num_columns+num_row_headings);
bb_table(1:3, (num_row_headings+1):end)=column_heading;
bb_table(4:end, 1:num_row_headings)=row_heading;
bb_table(4:end, (num_row_headings+1):end)=bb;
% Output the name of the metric
fprintf(fid, '%s\t\r\n', [s{1,1}.stats_description{stat_to_get(e8)}, ' For Each File']);
% Print the column headings
for e1=1:3;
for e2=1:(num_columns+num_row_headings);
fprintf(fid, '%s\t', bb_table{e1, e2});
end
if isequal(e1,1)
fprintf(fid, '\t%s', 'Number of Samples');
for e3=1:(num_vars-1); % Number of Variables (Number of Data Acquisition Systems)
fprintf(fid, '\t');
end
fprintf(fid, '\t');
elseif isequal(e1,3)
for e3=1:num_vars; % Number of Variables (Number of Data Acquisition Systems)
fprintf(fid, '\t%s', ['var', num2str(e3)]);
end
fprintf(fid, '\t');
else
for e3=1:num_vars; % Number of Variables (Number of Data Acquisition Systems)
fprintf(fid, '\t');
end
fprintf(fid, '\t');
end
fprintf(fid, '\r\n');
end
fprintf(fid, '\r\n');
% Print a summary of the descriptive statistics of the metrics from
% each data file.
for e1=1:num_files; % Data files
%num_channels=num_channels_a(e1, e3);
%num_diff_channels=num_diff_channels_a(e1, e3);
for e2=1:num_channels_array(e1); % Channels
e5=e1-1+sum(num_channels_array(1:e1))-num_channels_array(e1)+e2;
% Print the row headings
for e7=1:num_row_headings;
fprintf(fid, '%s\t', bb_table{e5+3, e7});
end
% Print the data
% Data Metrics
for e4=1:num_metrics;
% Number of Variables (Number of Data Acquisition Systems)
for e3=1:num_vars;
num_channels=num_channels_a(e1, e3);
num_diff_channels=num_diff_channels_a(e1, e3);
sum_num_channels=sum_num_channels_a(e1, e3);
if ~isempty(s{e1,e3}) && logical(e2 <= sum_num_channels)
e6=(num_vars+1)*(e4-1)+e3;
fprintf(fid, '%s\t', bb_table{e5+3, e6+num_row_headings});
else
fprintf(fid, '\t');
end
end
fprintf(fid, '\t');
end
% Number of Variables (Number of Data Acquisition Systems)
for e3=1:num_vars;
switch flag
case 1
if e2 <= num_channels
fprintf(fid, '%i\t', num_samples_ca{e1, e3}(e2, 1));
end
case 2
if e2 <= num_diff_channels
fprintf(fid, '%i\t', num_samples_ca{e1, e3}(e2, 1));
end
case 3
if e2 <= num_channels
fprintf(fid, '%i\t', num_samples_ca{e1, e3}(e2, 1));
elseif e2-num_channels <= num_diff_channels
fprintf(fid, '%i\t', num_samples_ca{e1, e3}(e2-num_channels, 1));
end
otherwise
if e2 <= num_channels
fprintf(fid, '%i\t', num_samples_ca{e1, e3}(e2, 1));
elseif e2-num_channels <= num_diff_channels
fprintf(fid, '%i\t', num_samples_ca{e1, e3}(e2-num_channels, 1));
end
end
end
fprintf(fid, '\r\n');
end
fprintf(fid, '\r\n');
end
fprintf(fid, '\r\n');
mean_vals=cell(length(stat_to_get2),1);
max_num_channels=cell(length(stat_to_get2),1);
max_num_diff_channels=cell(length(stat_to_get2),1);
% Stats across channels
for e9=1:length(stat_to_get2);
[fid, mean_vals{e9, 1}, max_num_channels{e9, 1}, max_num_diff_channels{e9, 1}]=print_channel_stats(s, fid, flag, max_channels, num_metrics, num_vars, num_files, stat_to_get(e8), stat_to_get2(e9), num_channels_a, sum_num_channels_a, num_diff_channels_a, ratio_metrics, round_kind, round_digits);
fprintf(fid, '\r\n');
end
% Overall statistics, Stats across files for each channel
for e9=1:length(stat_to_get2);
[fid]=print_overall_stats(fid, s, flag, mean_vals{e9, 1}, max_num_channels{e9, 1}, max_num_diff_channels{e9, 1}, num_metrics, num_vars, stat_to_get2(e9), ratio_metrics, round_kind, round_digits);
fprintf(fid, '\r\n');
end
fprintf(fid, '\r\n\r\n\r\n');
end
fclose(fid);
|
|