1function [Stat] = VectStat (M) 2% 3% [Stat] = VectStat (M) 4% 5%Purpose: 6% calculates very basic stats of vectors 7% 8% 9%Input Parameters: 10% M : MxN matrix 11% NAN or Inf values are not considered and the user is warned of their existence 12% 13%Output Parameters: 14% 15% Stat is an Mx1 vector of structures with the following fields 16% Each Stat(i) has the following structures 17% .N : the number of elements in M(i,:) 18% .M : the mean of vector M(i,:) 19% .Md: the median of vector M(i,:) 20% .S : the (unbiased) standard deviation of M(i,:) 21% .V : the variance (S^2) of M(i,:) 22% .mx: The maximum value 23% .mn: The minimum value 24% 25% if the input vector is empty , NaN values are returned in Stat 26%More Info : 27% 28% 29% 30% 31% Author : Ziad Saad 32% Date : Tue Apr 20 17:13:23 CDT 1999 33 34 35%Define the function name for easy referencing 36FuncName = 'VectStat'; 37 38%Debug Flag 39DBG = 1; 40Stat.N = NaN; 41Stat.M = NaN; 42Stat.Md = NaN; 43Stat.S = NaN; 44Stat.V = NaN; 45 46 47 48if (is_row(M) ~= -1), 49 sZ = 1; 50 sz2 = length(M); 51 M = M(:)'; %turn M into a row vector 52else 53 sZ = size(M,1); 54 sz2 = size(M,2); 55end 56 57if (sZ == 0 | sz2 ==0), 58 ErrEval(FuncName,'Wrn_Empty M returning NaN structure for result'); 59 return; 60end 61 62%initialize, once 63 Stat(sZ).N = 0;Stat(sZ).M = 0;Stat(sZ).Md = 0;Stat(sZ).S = 0;Stat(sZ).V = 0; Stat(sZ).mn = 0; Stat(sZ).mx = 0; 64 65for (i=1:1:sZ), 66 igood = find(isfinite(M(i,:))); 67 N_igood = length(igood); 68 if (N_igood < sz2), 69 stmp = sprintf ('%s Warning: Inf or Nan ignored in row %g\n', FuncName, i); 70 end 71 72 Stat(i).N = N_igood; 73 Stat(i).M = mean(M(i,igood)); 74 Stat(i).Md = median(M(i,igood)); 75 Stat(i).S = std(M(i,igood),0); %unbiased estimator 76 Stat(i).V = Stat(i).S .^ 2; 77 Stat(sZ).mn = min(M(i,igood)); 78 Stat(sZ).mx = max(M(i,igood)); 79end 80 81 82return; 83 84