0001 function [Y,Yvar,o] = summary_data(o, sumfunc_str)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if nargin > 1
0023 o = sumfunc(o, sumfunc_str);
0024 end
0025 s_f = sumfunc(o);
0026 if isempty(s_f)
0027 error('No summary function specified');
0028 end
0029
0030
0031 st = y_struct(o);
0032
0033
0034
0035 if nargin > 1 | ...
0036 ~isfield(st, 'Y') | ...
0037 (nargout > 2 & ~isfield(st, 'Yvar'))
0038
0039
0040 Ys = region_data(o);
0041 sz = summary_size(o);
0042 if isempty(Ys)
0043 error('No region data to summarize');
0044 elseif region_size(o, 'all', 2) == sz(2)
0045 Y = [Ys{:}];
0046 Yvar = ones(sz) * Inf;
0047 else
0048 if strcmp(s_f, 'unknown')
0049 error('Cannot recalculate from unknown sumfunc');
0050 end
0051 Ws = region_weights(o);
0052 Y = zeros(sz);
0053 Yvar = zeros(sz);
0054 for i = 1:sz(2);
0055 if isempty(Ys{i})
0056 Y(:,i) = NaN;
0057 Yvar(:,i) = NaN;
0058 else
0059 [Y(:,i) Yvar(:,i)] = pr_sum_func(Ys{i}, s_f, Ws{i});
0060 end
0061 end
0062 if verbose(o)
0063 fprintf('Summarizing data with summary function: %s\n', s_f);
0064 end
0065 end
0066 if nargout > 2
0067 st.Y = Y;
0068 st.Yvar = Yvar;
0069 o = y_struct(o, st);
0070 end
0071 else
0072 Y = st.Y;
0073 if nargout > 1
0074 Yvar = st.Yvar;
0075 end
0076 end
0077
0078