TFR Analysis - Plotting Problem

Lars Kosubek kosubek at CBS.MPG.DE
Thu Jun 28 00:24:11 CEST 2007


Dear Fieldtrip-Team,

I'm trying to use fieldtrip-toolbox since a few days. After working
through the tutorials and fixing the problem of  matlab crash while
importing eep-probe files i tried to do tfr-analysis. Everything seems
fine but if the script reaches the part of plotting i get the following
fault:


--------------------------------------------------------
??? Index exceeds matrix dimensions.

Error in ==> topoplotER at 289
  dat = dat(:, ymin:ymax, xmin:xmax);
--------------------------------------------------------



What could be the reason of this problem? Maybe used the sub functions not
in the right way...?

In hope someone could spend a bit time in helping me, i will add the hole
analysis-script:


--------------------------------------------------------
debug=1

Path='/scr/fabian1/lars/SPROD/data/EEP/sprod';

%Subjects={'01','02','03','04','06','07','10','11','12','14','15', ...
%    '16','17','18','19','20','21','22','23','24'};

Channels={'F3','FZ','F4','FC3','FCZ','FC4','C3','CZ',  ...
        'C4','CP3','CPZ','CP4','P3','PZ','P4',};

%Contrasts={ {'33','31'} {'63','33'}}

Subjects={'01','02'}

Contrasts={ {'33','31'} }

%Channels={'all'}


%% 1. Import files (select trials, reject & preprocess)

for k=1:length(Contrasts), Conditions=Contrasts{k};
  for j=1:length(Conditions), Condition=Conditions{j};
    for i=1:length(Subjects), Subject=Subjects{i};
        cfg = [];
        cfg.dataset                 = strcat(Path, Subject, '.cnt');
        cfg.trialdef.eventtype      = 'trigger';
        cfg.trialdef.prestim        = 1;
        cfg.trialdef.poststim       = 2;
        cfg.trialdef.eventvalue     = Condition;
        cfg                         = definetrial(cfg);

        cfg.rejectfile=strcat(Path, Subject, '.rej')
        %[cfg] = rejectartifact(cfg);  nor included in preprocessing

        cfg.channel    = Channels;
        %cfg.detrend    = 'yes';
        PreProcData{i,j,k}  = preprocessing(cfg);
        %save PreProcData PreProcData{i,j,k} -append;
    end
  end
end


%% 2. TimeFrequenzyResolution per Subject an Condition

for k=1:length(Contrasts), Conditions=Contrasts{k};
  for j=1:length(Conditions), Condition=Conditions{j};
    for i=1:length(Subjects), Subject=Subjects{i};
        cfg              = [];
        cfg.output       = 'pow';
        %cfg.channel      = 'all';
        cfg.method       = 'mtmconvol';
        cfg.taper        = 'hanning';
        cfg.foi          = 1:1:20;
        cfg.t_ftimwin    = ones(length(cfg.foi),1).*0.5;
        %cfg.t_ftimwin    = 5./cfg.foi;  % 7 cycles per time window
        cfg.toi          = -1:0.05:2;
        cfg.keeptrials   = 'no';
        cfg.keeptapers   = 'no';

        TFRAvgData{i,j,k}  = freqanalysis(cfg, PreProcData{i,j,k})
        %save TFRAvgData TFRAvgData{i,j,k} -append;
        if debug==1
        cfg = [];
        cfg.layout         = 'EEG1010.lay';
        cfg.zparam='powspctrm';
        cfg.xparam='time';
        cfg.yparam='freq';
        %cfg.xlim = -0.2 : 0.1 : 1.0;      % Define 12 time intervals
        %cfg.zlim = [-1.3e-13 1.3e-13];    % Set the 'color' limits.
        figure; multiplotTFR(cfg,TFRAvgData{i,j,k})
        end
    end
  end
end


clear PreProcData;


%% 3. GrandAvarage of Conditions over Subjects

for k=1:length(Contrasts), Conditions=Contrasts{k};
    for j=1:length(Conditions), Condition=Conditions{j};
        cfg = [];
        cfg.keepindividual='yes';
        TFRGAvgData{k,j}  = freqgrandaverage(cfg, TFRAvgData{:,j,k})
        %save TFRGAvgData TFRGAvgData{i,j} -append;
    end
end


clear TFRAvgData;



%% 4. Cluster Based Permutation Statitic between Conditions

for k=1:length(Contrasts), Conditions=Contrasts{k};
cfg = [];
cfg.parameter='powspctrm'
cfg.latency=[0.2 1.4];
cfg.method = 'montecarlo';
cfg.statistic = 'depsamplesT';
cfg.clusteralpha = 0.05;
cfg.clusterstatistic = 'maxsum';
cfg.minnbchan = 2;
cfg.tail = 0;
cfg.clustertail = 0;
cfg.alpha = 0.05;
cfg.numrandomization = 100;
cfg.layout         = 'EEG1010.lay';

subj = length(Subjects);
design=zeros(2,2*subj);
for s = 1:subj
  design(1,s) = s;
end
for s = 1:subj
  design(1,subj+s) = s;
end
design(2,1:subj)        = 1;
design(2,subj+1:2*subj) = 2;

cfg.design   = design;
cfg.uvar  = 1;
cfg.ivar  = 2;

[stat] = freqstatistics(cfg, TFRGAvgData{k,1}, TFRGAvgData{k,2})



%% 5. Plotting the Statistics

GA_TFR_AvsB = TFRGAvgData{k,1};
GA_TFR_AvsB.powspctrm =  GA_TFR_AvsB.powspctrm - TFRGAvgData{k,2}.powspctrm;


figure;
j = [-0.4:0.05:1.35];
foi = 10;  % frequency of interest
index_foi = find(stat.freq==foi);% index of frequency of interest in stat
for k = 1:11;
     m=k+16;
     subplot(4,5,k);
     cfg = [];
     %cfg.baseline   = [-0.5 -0.1];
     cfg.xlim=[j(k) j(k)];
     cfg.ylim = [foi foi];
     cfg.highlight = find (stat.negclusterslabelmat(:,index_foi,m)==1);
     %cfg.zlim = [-2.5e-28 2.5e-28];
     cfg.comment = 'xlim';
     cfg.commentpos = 'title';
     cfg.xparam='time';
     cfg.yparam='freq';
     cfg.zparam='powspctrm';
     cfg.layout='EEG1010.lay';

     topoplotTFR(cfg, GA_TFR_AvsB);
end

end
------------------------------------------------------------------

Big Thanks for taking time and reading until this point!
Best Regards, Lars Kosubek

----------------------------------
The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also http://listserv.surfnet.nl/archives/fieldtrip.html and http://www.ru.nl/fcdonders/fieldtrip.



More information about the fieldtrip mailing list