??? Index exceeds matrix dimensions.
Mostra commenti meno recenti
Dear all,
I'm new here and I'm adjusting a script from someone else to fit my needs. I keep getting an error while running this script: ??? Index exceeds matrix dimensions.
I'm sorry to bother with what may be a silly question, but I'm a true newbie.
%--------------------------------------------------------------------------
% CONFIRM BAD TRIALS
% FIND BAD CHANNELS
%--------------------------------------------------------------------------
clear all
addpath(genpath('C:\Program Files (x86)\MATLAB\R2011a\toolbox\fieldtrip20120404'))
cd 'D:\EMCL\MY THESIS\EEG PT\DATA\'
InfoSubjects
InfoExperiment
[rw,cl] = size (Infosubjects); clear cl
for j = 1:rw
%----------------------------------------------------------------------
% LOAD EVENTS AND TRL
%----------------------------------------------------------------------
load(sprintf('%s%s%s',info.expname,Infosubjects{j,2},'\EVENTS.mat'));
load(sprintf('%s%s%s',info.expname,Infosubjects{j,2},'\TRL.mat'));
hdr = ft_read_header(sprintf('%s%s\\%s\\%s%s',info.expname,Infosubjects{j,2},Infosubjects{j,3},Infosubjects{j,2},info.filename));
%----------------------------------------------------------------------
% CONFIRM BAD TRIALS AND FIND BAD CHANNELS
%----------------------------------------------------------------------
cfg = [];
cfg.dataset = sprintf('%s%s\\%s\\%s%s',info.expname,Infosubjects{j,2},Infosubjects{j,3},Infosubjects{j,2},info.filename);
Trl_p = []; cfg.trl = [0 0 0];
for c = 1:info.conditions.number
Trl_p = Trl{c}; cfg.trl = [cfg.trl;Trl_p];
end
clear Trl_p
cfg.trl = cfg.trl(2:length(cfg.trl),:); cfg.channel = hdr.label(1:info.nC);
cfg.blc = 'yes'; Confirm = ft_preprocessing(cfg);
cfg = []; cfg.method = 'summary'; Confirm = ft_rejectvisual(cfg, Confirm);
Channels_good = Confirm.label; Bad_Channels={}; i=1; p=1;
while i < length(Confirm.cfg.channel)
if strcmp (Confirm.cfg.channel(i,1),Confirm.label(p,1));
i = i + 1; p = p + 1;
else
Bad_Channels(end+1,:)= Confirm.cfg.channel(i,1);
i = i + 1;
end
end
clear Channels Channels_good
juju=[];
for i = 1:length(Confirm.cfg.trl)-1
if Confirm.cfg.trl(i,1) > Confirm.cfg.trl(i+1,1)
juju (end+1, :) = i;
end
end
juju = [0;juju;length(Confirm.cfg.trl)];
for c = 1:info.conditions.number
Trl_p = [Confirm.cfg.trl(juju(c)+1:juju(c+1),1:3)];
Trl{c} = Trl_p;
end
clear Trl_p
%----------------------------------------------------------------------
% Count and save the trials numbers where were found artifacts
%----------------------------------------------------------------------
Trl_p = [];
for c = 1:info.conditions.number
for r = 1:info.responses.number
for i = 1:length(events_clean)
if strcmp(num2str(events_clean(i).value), info.conditions.marker(c))
% if the experimental condition is defined for more than one marker,
% please define here the right criterion and appdate in InfoExperiment info.conditions
% if strcmp(num2str(events_clean(i+info.mbsr).value), info.responses.correct.marker(r))
begsample = events_clean(i).sample + info.begintime*hdr.Fs;
endsample = events_clean(i+info.mbsr).sample + 0*hdr.Fs - 1;
offset = + info.begintime*hdr.Fs;
Trl_p(end+1, :) = round([begsample endsample offset]);
end
end
end
end
end
Trl_p = sortrows(Trl_p);
clear i begsample endsample offset events_clean
[f,u] = size(Confirm.cfg.artifact); Last_Rejected=[];
for i =1:length(Trl_p);
for p = 1:f
if Trl_p(i,1) == Confirm.cfg.artifact(p,1);
Last_Rejected(end+1,:) = i;
end
end
end
Artifacts = Confirm.cfg.artifact;
if isempty(Artifacts)
Artifacts = 'no additional trials rejected'; Last_Rejected = 0;
end
clear Trl_p c f i Confirm p u juju cfg
%----------------------------------------------------------------------
% SAVE THE NUMBER OF TRIALS IN AN EXCEL FILE
% SAVE THE Artifacts_Conf.mat
% SAVE THE Bad_Channels.mat
%----------------------------------------------------------------------
cd(sprintf('%s%s\\%s',info.expname,Infosubjects{j,2},Infosubjects{j,4}));
xlswrite('rejectedtrials.xls', Last_Rejected, 'Last_Rejected');
save Artifacts_Conf Artifacts
save Bad_Channels Bad_Channels
cd(sprintf('%s\\%s',info.expname,Infosubjects{j,2}));
save TRL Trl
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!