-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrex_next_trial.m
84 lines (72 loc) · 2.22 KB
/
rex_next_trial.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function [nexttrial, islast] = rex_next_trial( name, trial, includebad )
% [nexttrial, islast] = rex_next_trial( name, trial, includebad )
%
% Given a data set name (the name of the original REX data and/or the
% matlab data file), and a trial number, return the number (just the
% number) of the next sequential trial. If the optional 3rd parameter
% 'includebad' is set to 1, then this is simply trial + 1. If the 3rd
% parameter is 0 (the DEFAULT), then a search forward is done for the next
% good trial (the next trial not marked as BAD), and rex_next_trial()
% returns that number.
% In either instance, if no next trial number can be returned (the trial
% value passed in is already the last one) then nexttrial is 0 and islast
% is set to 1.
%
% EXAMPLE:
%
% rexname = 'monkeydata'; % This will look for 'monkeydata.mat' or
% % 'monkeydataA' and '...E'
% rex_load_processed( rexname );
% trial = rex_first_trial( rexname );
% if trial > 0
% islast = 0;
% while ~islast
% [... make calls to things like rex_trial( rexname, trial ) to get
% data for this trial ...]
% [trial, islast] = rex_next_trial( rexname, trial );
% end;
% end;
%
% Add a 1 as another parameter when calling rex_first_trial() and
% rex_next_trial(), and this example will look at all trials, not just
% those that are good (not marked as BAD).
global rexnumtrials;
if nargin < 3
includebad = 0;
end;
nexttrial = trial;
badtrial = 1;
islast = 0;
num = rexnumtrials; %num_rex_trials( name );
if trial >= num
nexttrial = 0;
islast = 1;
return;
end;
if includebad
nexttrial = nexttrial + 1;
% if nexttrial == num
% islast = 1;
% end;
return;
end;
while badtrial && nexttrial < num
nexttrial = nexttrial + 1;
badtrial = rex_is_bad_trial( name, nexttrial );
end;
% If no more good trials can be found, then badtrial will come out of the
% above loop still true. It means that trial is already the last trial.
if badtrial
nexttrial = 0;
islast = 1;
return;
end;
% % Is this the last good trial?
%
% islast = 1;
% for d = nexttrial+1:num
% badtrial = rex_is_bad_trial( name, d );
% if ~badtrial
% islast = 0;
% end;
% end;