From: Jesse on 19 May 2010 22:16 I've seen other people ask similar questions, but still don't understand why this isn't working. The specific error is: Attempted to access times(1); index out of bounds because numel(times)=0. It occurs in a utility file from Plexon called plx2trials. **Below is the full code:** function data = plx2trials(TimesEvents); % Function for parsing an Nx2 matrix of time stamps and corresponding % event codes into a cell array format compatible with the data structure % generated by the function ctx2mat. % % INPUT FORMAT: % TimesEvents(:,1) = time stamps. % TimesEvents(:,2) = event codes. % % OUTPUT FORMAT % for each trial T, % data{T}{1} contains spike time stamps, relative to trial onset. % data{T}{2} contains spike event codes corresponding to those time stamps. % % Note that events marking the beginning and end of the trial are not % returned, as it is assumed that they are already recovered from ctx2mat. % % last modified 041001 % dbtm STARTCODE = 100; STOPCODE = 101; data = []; % PARSE TE INTO A CORTEX-LIKE DATA STRUCTURE BeginTrial = find(TimesEvents(:,2)==STARTCODE); EndTrial = find(TimesEvents(:,2)==STOPCODE); for t = 1:length(BeginTrial) times = TimesEvents(BeginTrial(t):EndTrial(t),1); codes = TimesEvents(BeginTrial(t):EndTrial(t),2); times = times-times(1); if length(times)>2 data{t}{1} = times(2:length(times)-1)'; data{t}{2} = codes(2:length(codes)-1)'; else data{t}{1} = []; data{t}{2} = []; end end **End of code** The error happens in the line : times = times-times(1); TimesEvents is a 2489x2 double when it chokes. And 'times' as well as 'codes' are 56x1 doubles. First few cells of 'times': 0 10 22 26 69 70 71 76 It works just fine with other data sets. I'm really confused. Jesse
From: dpb on 19 May 2010 22:26 Jesse wrote: > I've seen other people ask similar questions, but still don't understand > why this isn't working. > The specific error is: Attempted to access times(1); index out of bounds > because numel(times)=0. > It occurs in a utility file from Plexon called plx2trials. > .... > STARTCODE = 100; > STOPCODE = 101; > > data = []; > > % PARSE TE INTO A CORTEX-LIKE DATA STRUCTURE > BeginTrial = find(TimesEvents(:,2)==STARTCODE); > EndTrial = find(TimesEvents(:,2)==STOPCODE); > for t = 1:length(BeginTrial) > times = TimesEvents(BeginTrial(t):EndTrial(t),1); > codes = TimesEvents(BeginTrial(t):EndTrial(t),2); > times = times-times(1); .... > The error happens in the line : times = times-times(1); > .... > It works just fine with other data sets. I'm really confused. Jesse W/O dataset itself it's hard to confirm for absolute certain but it would seem the problem would have to be that the find() operation didn't retrun an EndTrial>=BeginTrial so that as the error says, there are no elements in the times array to begin with. Hence, trying to address the first element of a null array fails. Try removing the semicolons from the two lines BeginTrial = find(TimesEvents(:,2)==STARTCODE) EndTrial = find(TimesEvents(:,2)==STOPCODE) And rerun on a failing dataset. An error check there might be a useful feature. --
From: Jesse on 19 May 2010 22:37 dpb <none(a)non.net> wrote in message <ht26on$hga$1(a)news.eternal-september.org>... > W/O dataset itself it's hard to confirm for absolute certain but it > would seem the problem would have to be that the find() operation didn't > retrun an EndTrial>=BeginTrial so that as the error says, there are no > elements in the times array to begin with. Hence, trying to address the > first element of a null array fails. This isn't the case. The first cell in 'codes' is 100 (the start code) and the 56th cell is 101 (the stop code). There IS data in 'times.' Is the problem that the first cell in 'times' is 0? Because, logically, it Should be.
From: Jesse on 19 May 2010 23:26 "Jesse " <jsheehan(a)cnbc.cmu.edu> wrote in message <ht278f$eug$1(a)fred.mathworks.com>... > dpb <none(a)non.net> wrote in message <ht26on$hga$1(a)news.eternal-september.org>... > >Try removing the semicolons from the two lines > >BeginTrial = find(TimesEvents(:,2)==STARTCODE) >EndTrial = find(TimesEvents(:,2)==STOPCODE) > I took this suggestion, and here is the last set it displayed: times = 470744 470744 470799 470813 470815 470818 470822 470828 470840 470990 471100 471239 471245 471273 471373 471520 471556 471683 471875 471905 471949 472011 472151 472160 472190 472373 472399 472587 472666 472800 472989 473013 473171 473179 473226 473234 473373 473440 473812 473856 473923 473992 474029 474127 474272 474338 474373 474400 474418 474457 474512 474605 474733 474768 474799 474834 474946 codes = 100 1001 1002 1001 202 1001 1001 1001 1001 1001 1002 1002 1001 1002 1002 1001 1001 1001 1002 1001 1002 1002 1002 1001 1002 1001 1002 1002 1001 1001 1002 1001 1002 1001 1001 1001 1001 1001 1001 1001 1001 1002 1002 1001 1001 1002 1002 1002 1001 1001 1002 1002 1001 1002 1001 1001 101 times = Empty matrix: 0-by-1 codes = Empty matrix: 0-by-1 ******** Why did they both suddenly go blank?
From: dpb on 20 May 2010 09:54 Jesse wrote: > "Jesse " <jsheehan(a)cnbc.cmu.edu> wrote in message > <ht278f$eug$1(a)fred.mathworks.com>... >> dpb <none(a)non.net> wrote in message >> <ht26on$hga$1(a)news.eternal-september.org>... >> >> Try removing the semicolons from the two lines >> >> BeginTrial = find(TimesEvents(:,2)==STARTCODE) >> EndTrial = find(TimesEvents(:,2)==STOPCODE) >> > > I took this suggestion, and here is the last set it displayed: > > times = > > 470744 > 470744 .... > 474799 > 474834 > 474946 > > > codes = > > 100 > 1001 > 1002 .... > 1001 > 1001 > 101 > > > times = > > Empty matrix: 0-by-1 > > > codes = > > Empty matrix: 0-by-1 > ******** > Why did they both suddenly go blank? Well, it isn't _exactly_ what I suggested, that's the result of the two lines in the loop, not the two find() operations. Here's your code snippit again... % PARSE TE INTO A CORTEX-LIKE DATA STRUCTURE BeginTrial = find(TimesEvents(:,2)==STARTCODE); EndTrial = find(TimesEvents(:,2)==STOPCODE); for t = 1:length(BeginTrial) times = TimesEvents(BeginTrial(t):EndTrial(t),1); codes = TimesEvents(BeginTrial(t):EndTrial(t),2); ... It's clear the second pass fails since the first time the two arrays are not empty. Again, instead of looking at the times and codes arrays alone, look at BeginTrial = find(TimesEvents(:,2)==STARTCODE) EndTrial = find(TimesEvents(:,2)==STOPCODE) I'm quite sure you'll find a problem there in the second instance for this data set. --
|
Next
|
Last
Pages: 1 2 Prev: Ant colony algorithm (ACO) Next: to check presence of image in a folder |