0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 function multiplot_tfrGND(tfrGND,varargin)
0106
0107 p=inputParser;
0108 p.addRequired('tfrGND',@isstruct);
0109 p.addParamValue('bin','1',@(x) ischar(x) || isnumeric(x));
0110 p.addParamValue('freq_limits',[],@(x) isnumeric(x) && length(x)==2);
0111 p.addParamValue('time_limits',[],@(x) isnumeric(x) && length(x)==2);
0112 p.addParamValue('color_limits',[],@(x) (isnumeric(x) && length(x)==2) || ischar(x));
0113 p.addParamValue('exclude_chans',[],@(x) ischar(x) || iscell(x));
0114 p.addParamValue('include_chans',[],@(x) ischar(x) || iscell(x));
0115 p.addParamValue('sub_id',[],@(x) isnumeric(x) && (length(x)==1) && (x>0));
0116 p.addParamValue('fig_id',[],@(x) isnumeric(x) && length(x)==1);
0117 p.addParamValue('test_id',0,@(x) isnumeric(x) && length(x)==1);
0118 p.addParamValue('interactive','yes',@ischar);
0119 p.addParamValue('units',[],@(x) strcmpi(x,'dB') || strcmpi(x,'raw'));
0120 p.addParamValue('bsln_wind',[],@(x) isnumeric(x) && length(x)==2);
0121 p.addParamValue('bsln_type',[],@(x) strcmpi(x,'relative') || strcmpi(x,'absolute'));
0122 p.addParamValue('p_value_mask',[],@(x) isnumeric(x) && length(x)==1);
0123
0124 p.parse(tfrGND,varargin{:});
0125
0126
0127 bsln_wind=p.Results.bsln_wind;
0128 bsln_type=p.Results.bsln_type;
0129 units=p.Results.units;
0130
0131
0132
0133 n_subs=size(tfrGND.indiv{1},1);
0134 if ~isempty(p.Results.sub_id) && (p.Results.sub_id>n_subs),
0135 error('You requested to plot Subject %d''s data this tfrGND variable only contains data for %d subjects.', ...
0136 p.Results.sub_id,n_subs);
0137 end
0138
0139
0140
0141
0142 if p.Results.test_id,
0143 n_tests=length(tfrGND.stats);
0144 if p.Results.test_id>n_tests,
0145 error('You requested Test %d, but you only have %d tests in this tfrGND variable.', ...
0146 p.Results.test_id,n_tests);
0147 end
0148 if ~strcmpi(tfrGND.stats{p.Results.test_id}.dimord,'chan_freq_time')
0149 error(['"dimord" field of this test is not ''chan_freq_time''. This leads me to believe this test was performed after averaging over time points or frequencies. ', ...
0150 'multiplot_tfrGND.m cannot plot the result of such an analysis.']);
0151 end
0152 if length(tfrGND.stats{p.Results.test_id}.label)==1,
0153
0154 if ismember('+',tfrGND.stats{p.Results.test_id}.label{1})
0155
0156 error('This test was performed on the average across multiple channels. Using singeplot_tfrGND.m instead.');
0157 end
0158 end
0159 plot_bins=tfrGND.stats{p.Results.test_id}.bins;
0160 if isempty(p.Results.freq_limits)
0161 freq_limits=[tfrGND.stats{p.Results.test_id}.freq(1) tfrGND.stats{p.Results.test_id}.freq(end)];
0162 else
0163 freq_limits=p.Results.freq_limits;
0164 end
0165 if isempty(p.Results.time_limits)
0166 time_limits=tfrGND.stats{p.Results.test_id}.cfg.latency;
0167 else
0168 time_limits=p.Results.time_limits/1000;
0169 end
0170
0171
0172 units=tfrGND.stats{p.Results.test_id}.units;
0173 bsln_wind=tfrGND.stats{p.Results.test_id}.bsln_wind;
0174 bsln_type=tfrGND.stats{p.Results.test_id}.bsln_type;
0175
0176 if isempty(p.Results.p_value_mask)
0177 p_mask=tfrGND.stats{p.Results.test_id}.family_alpha;
0178 else
0179 p_mask=p.Results.p_value_mask;
0180 fprintf('Using requested p-value threshold of %g to mask out data instead of the test p-value of %g\n', ...
0181 p_mask,tfrGND.stats{p.Results.test_id}.family_alpha);
0182 end
0183
0184 n_test_chans=length(tfrGND.stats{p.Results.test_id}.label);
0185 n_all_chans=length(tfrGND.ftrip.label);
0186 if n_all_chans~=n_test_chans,
0187 test_chan_ids=zeros(1,n_test_chans);
0188 cfg.channel=cell(1,n_test_chans);
0189 for a=1:n_test_chans,
0190 test_chan_ids(a)=find(ismember(tfrGND.ftrip.label,tfrGND.stats{p.Results.test_id}.label{a}));
0191 cfg.channel{a}=tfrGND.stats{p.Results.test_id}.label{a};
0192 end
0193 else
0194 test_chan_ids=1:n_all_chans;
0195 end
0196 else
0197
0198 plot_bins=p.Results.bin;
0199 if isempty(p.Results.freq_limits),
0200 freq_limits=[tfrGND.ftrip.freq(1) tfrGND.ftrip.freq(end)];
0201 else
0202 freq_limits=p.Results.freq_limits;
0203 end
0204 if isempty(p.Results.time_limits),
0205 time_limits=[tfrGND.ftrip.time(1) tfrGND.ftrip.time(end)];
0206 else
0207 time_limits=p.Results.time_limits;
0208 end
0209
0210
0211 if ~isempty(p.Results.include_chans),
0212 if ~isempty(p.Results.exclude_chans),
0213 error('You cannot use both ''exclude_chans'' AND ''include_chans'' options.');
0214 end
0215
0216 if ischar(p.Results.include_chans),
0217
0218 error('If you only want to plot one channel, use singleplot_tfrGND.m instead.');
0219 else
0220 cfg.channel=p.Results.include_chans;
0221 end
0222 n_req_chan=length(cfg.channel);
0223
0224 for a=1:n_req_chan,
0225 if ~ismember(cfg.channel{a},tfrGND.ftrip.label)
0226 error('There is no channel called %s in this tfrGND variable.',cfg.channel{a});
0227 end
0228 end
0229 elseif ~isempty(p.Results.exclude_chans),
0230
0231 if ischar(p.Results.exclude_chans),
0232 exclude_chans{1}=p.Results.exclude_chans;
0233 else
0234 exclude_chans=p.Results.exclude_chans;
0235 end
0236 n_req_chan=length(exclude_chans);
0237 cfg.channel=cell(1,n_req_chan+1);
0238 cfg.channel{1}='all';
0239 for a=1:n_req_chan,
0240
0241 if ~ismember(exclude_chans{a},tfrGND.ftrip.label)
0242 error('There is no channel called %s in this tfrGND variable.',exclude_chans{a});
0243 else
0244
0245 cfg.channel{a+1}=['-' exclude_chans{a}];
0246 end
0247 end
0248 end
0249 end
0250
0251
0252 if isempty(bsln_wind),
0253 bsln_wind=tfrGND.bsln_wind;
0254 end
0255 if isempty(bsln_type),
0256 bsln_type=tfrGND.bsln_type;
0257 end
0258 if isempty(units),
0259 units=tfrGND.units;
0260 end
0261
0262
0263 n_bins=length(tfrGND.bindesc);
0264
0265
0266 neg_id=find(plot_bins=='-');
0267 if ismember('-',plot_bins),
0268 bin1=str2double(plot_bins(1:(neg_id-1)));
0269 bin2=str2double(plot_bins((neg_id+1):end));
0270
0271 if isempty(bin1) || isempty(bin2),
0272 error('%s is not a valid bin request.',plot_bins);
0273 elseif bin1>n_bins,
0274 error('You only have %d bins in this tfrGND variable but you requested Bin %d.',n_bins,bin1);
0275 elseif bin2>n_bins,
0276 error('You only have %d bins in this tfrGND variable but you requested Bin %d.',n_bins,bin2);
0277 end
0278
0279
0280 if ~strcmpi(units,tfrGND.units) || ...
0281 ~isequal(bsln_wind,tfrGND.bsln_wind) || ...
0282 ~strcmpi(bsln_type,tfrGND.bsln_type)
0283 tfrGND=baseline_tfrGND(tfrGND,units,bsln_wind,bsln_type,[bin1 bin2]);
0284 end
0285
0286
0287 dif=1;
0288
0289 prefix=[tfrGND.bindesc{bin1} '-' tfrGND.bindesc{bin2}];
0290 if isempty(p.Results.sub_id),
0291
0292 tfrGND.ftrip.powspctrm=tfrGND.grands{bin1}-tfrGND.grands{bin2};
0293 suffix=['(Bin ' int2str(bin1) '-' int2str(bin2) ', Grand)'];
0294 else
0295
0296 tfrGND.ftrip.powspctrm=squeeze(tfrGND.indiv{bin1}(p.Results.sub_id,:,:,:))- ...
0297 squeeze(tfrGND.indiv{bin2}(p.Results.sub_id,:,:,:));
0298 suffix=['(Bin ' int2str(bin1) '-' int2str(bin2) ', Sub ' int2str(p.Results.sub_id) ')'];
0299 end
0300 else
0301 if ischar(plot_bins)
0302 bin=str2double(plot_bins);
0303 else
0304 bin=plot_bins;
0305 end
0306 if isempty(bin),
0307 error('%s is not a valid bin request.',plot_bins);
0308 end
0309
0310 if bin>n_bins,
0311 error('You only have %d bins in this tfrGND variable but you requested Bin %d.',n_bins,bin);
0312 end
0313
0314
0315 if ~strcmpi(units,tfrGND.units) || ...
0316 ~isequal(bsln_wind,tfrGND.bsln_wind) || ...
0317 ~strcmpi(bsln_type,tfrGND.bsln_type)
0318 tfrGND=baseline_tfrGND(tfrGND,units,bsln_wind,bsln_type,bin);
0319 end
0320
0321 dif=0;
0322
0323 prefix=tfrGND.bindesc{bin};
0324 if isempty(p.Results.sub_id),
0325
0326 tfrGND.ftrip.powspctrm=tfrGND.grands{bin};
0327 suffix=['(Bin ' int2str(bin) ', Grand)'];
0328 else
0329
0330 tfrGND.ftrip.powspctrm=squeeze(tfrGND.indiv{bin}(p.Results.sub_id,:,:,:));
0331 suffix=['(Bin ' int2str(bin) ', Sub ' int2str(p.Results.sub_id) ')'];
0332 end
0333 end
0334
0335 if isempty(p.Results.color_limits),
0336 cfg.zlim='maxmin';
0337 else
0338 cfg.zlim=p.Results.color_limits;
0339 end
0340 if dif,
0341 fprintf('Note, the power difference between conditions is always shown in decibels.\n');
0342 cfg.dB='no';
0343 end
0344 cfg.ylim=freq_limits;
0345 cfg.xlim=time_limits;
0346 cfg.showlabels='yes';
0347 cfg.interactive=p.Results.interactive;
0348 cfg.layout=tfrGND.ftrip.elec;
0349 cfg.elec=tfrGND.ftrip.elec;
0350
0351
0352
0353 if p.Results.test_id,
0354
0355 freq_ids=find_tpt(tfrGND.stats{p.Results.test_id}.freq(1),tfrGND.ftrip.freq): ...
0356 find_tpt(tfrGND.stats{p.Results.test_id}.freq(end),tfrGND.ftrip.freq);
0357 time_ids=find_tpt(tfrGND.stats{p.Results.test_id}.time(1),tfrGND.ftrip.time): ...
0358 find_tpt(tfrGND.stats{p.Results.test_id}.time(end),tfrGND.ftrip.time);
0359
0360
0361
0362 if 0
0363
0364
0365
0366
0367
0368 tfrGND.ftrip.powspctrm=tfrGND.ftrip.powspctrm(:,freq_ids,time_ids);
0369
0370
0371 if ~isequal(size(tfrGND.ftrip.powspctrm),size(tfrGND.stats{p.Results.test_id}.prob)),
0372 error('Size of spectrograms doesn''t equal the size of the p-value matrix from the statistical test.');
0373 end
0374
0375
0376 tfrGND.ftrip.powspctrm=tfrGND.ftrip.powspctrm.*(tfrGND.stats{p.Results.test_id}.prob<=p_mask);
0377 else
0378 if ~sum(sum(sum(tfrGND.stats{p.Results.test_id}.prob<=p_mask)))
0379 error('No comparisons have a p-value greater than the threshold of %g, thus all data will be masked out. Use a higher value of ''p_value_mask''.', ...
0380 p_mask);
0381 else
0382 tfrGND.ftrip.powspctrm(test_chan_ids,freq_ids,time_ids)=tfrGND.ftrip.powspctrm(test_chan_ids,freq_ids,time_ids).* ...
0383 (tfrGND.stats{p.Results.test_id}.prob<=p_mask);
0384 end
0385 end
0386 end
0387
0388
0389
0390 if isempty(p.Results.fig_id),
0391 figure('renderer','zbuffer'); ft_multiplotTFR(cfg,tfrGND.ftrip);
0392 else
0393 figure(p.Results.fig_id); clf; ft_multiplotTFR(cfg,tfrGND.ftrip);
0394 end
0395 set(gcf,'name',[prefix ' ' suffix]);
0396
0397