Home > marsbar > @marsy > summary_data.m

summary_data

PURPOSE ^

method to get summary data, maybe set sumfunc

SYNOPSIS ^

function [Y,Yvar,o] = summary_data(o, sumfunc_str)

DESCRIPTION ^

 method to get summary data, maybe set sumfunc
 
 Inputs
 o              - marsy data object
 sumfunc_str    - [optional] summary function string; one of
                  'mean', 'median', 'eig1', 'wtmean'
                  If not specified, defaults to previous summary
                  function for this object

 Output
 Y              - (re)calculated summary time course
 Yvar           - [optional] variance time course
 o              - possibly changed marsy data object

 e.g. 
 Y = summary_data(o);
 [Y Yvar o] = summary_data(o, 'median');
 
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Y,Yvar,o] = summary_data(o, sumfunc_str)
0002 % method to get summary data, maybe set sumfunc
0003 %
0004 % Inputs
0005 % o              - marsy data object
0006 % sumfunc_str    - [optional] summary function string; one of
0007 %                  'mean', 'median', 'eig1', 'wtmean'
0008 %                  If not specified, defaults to previous summary
0009 %                  function for this object
0010 %
0011 % Output
0012 % Y              - (re)calculated summary time course
0013 % Yvar           - [optional] variance time course
0014 % o              - possibly changed marsy data object
0015 %
0016 % e.g.
0017 % Y = summary_data(o);
0018 % [Y Yvar o] = summary_data(o, 'median');
0019 %
0020 % $Id$
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 % Get a copy of object structure
0031 st = y_struct(o);
0032 
0033 % refresh summary data if necessary
0034 % (if sumfunc passed, OR if data is not yet available)
0035 if nargin > 1 | ...              % sumfunc passed
0036       ~isfield(st, 'Y') | ...    % Y not yet calculated
0037       (nargout > 2 & ~isfield(st, 'Yvar')) % Yvar needed
0038   
0039   % If we only have one (or zero) columns per ROI, job is simple
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) % One column per ROI
0045     Y = [Ys{:}];
0046     Yvar = ones(sz) * Inf;
0047   else % More than one column per ROI
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}) % set to NaN if no data to summarize
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 % not recalculated
0072   Y = st.Y;
0073   if nargout > 1
0074     Yvar = st.Yvar;
0075   end
0076 end
0077 
0078 

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019