0001 function marsY = get_marsy(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 for r = 1:nargin
0020 if ~isa(varargin{r}, 'maroi')
0021 break
0022 end
0023 end
0024 rlen = r - 1;
0025 roi_array = varargin(1:rlen);
0026
0027 narg_left = nargin - rlen;
0028 if narg_left < 1
0029 VY = [];
0030 else
0031 VY = varargin{r};
0032 end
0033 if isempty(VY), error('Need images to extract from'); end
0034 if narg_left < 2
0035 sumfunc = '';
0036 else
0037 sumfunc = varargin{r+1};
0038 end
0039 if isempty(sumfunc), error('Need summary function'); end
0040 if narg_left < 3
0041 flags = '';
0042 else
0043 flags = varargin{r+2};
0044 end
0045 if isempty(flags), flags = ' '; end
0046 vf = any(flags == 'v');
0047
0048
0049 des_summary = 'None';
0050 if isa(VY, 'mardo')
0051 if ~has_images(VY)
0052 error('This design does not contain images');
0053 end
0054 D = VY;
0055 VY = get_images(VY);
0056 else
0057 D = [];
0058 end
0059
0060 if ischar(VY)
0061 if vf, fprintf('%-40s: ','Mapping files'); end
0062 VY = spm_vol(VY);
0063 if vf, fprintf('%30s\n','...done'); end
0064 end
0065
0066 if vf, fprintf('%-40s: %30s','Fetching data',' '); end
0067 rlen = length(roi_array);
0068 rno = 0;
0069 for r = 1:rlen
0070 if vf
0071 fprintf('%s%30s',...
0072 repmat(sprintf('\b'),1,30),...
0073 sprintf('%4d/%-4d',r, rlen));
0074 end
0075 o = roi_array{r};
0076 [y vals vXYZ mat] = getdata(o, VY);
0077 [ny nvals] = size(y);
0078 if isempty(y)
0079 if vf, fprintf('\n'); end
0080 warning(sprintf('No valid data for roi %d (%s)', r, label(o)));
0081 if vf & (r < rlen), fprintf('%-40s: %30s','Fetching data',' '); end
0082 else
0083 rno = rno + 1;
0084
0085 if all(vals == 1)
0086 vals = [];
0087 end
0088 r_data{rno} = y;
0089 r_info{rno} = struct(...
0090 'name', label(o),...
0091 'descrip', descrip(o),...
0092 'weights', vals,...
0093 'info', struct('file', source(o)),...
0094 'vXYZ', vXYZ,...
0095 'mat', mat);
0096 if rno < 2, lbl = label(o); else lbl = [lbl ' & ' label(o)]; end
0097 end
0098 end
0099 if vf, fprintf('%s%30s\n',repmat(sprintf('\b'),1,30),'...done'); end
0100
0101 if rno == 0
0102 marsY = [];
0103 return;
0104 end
0105
0106 s_info = struct(...
0107 'sumfunc', sumfunc, ...
0108 'descrip', ['Data from ' lbl],...
0109 'info', struct('VY', VY));
0110
0111
0112 if ~isempty(D)
0113 s_info.info.des_summary = summary(D);
0114 s_info.info.TR = tr(D);
0115 s_info.block_rows = block_rows(D);
0116 end
0117
0118 marsY = marsy(r_data, r_info, s_info);