-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConvertConditionToJPFormat.m
More file actions
50 lines (40 loc) · 1.52 KB
/
Copy pathConvertConditionToJPFormat.m
File metadata and controls
50 lines (40 loc) · 1.52 KB
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
function ConvertConditionToJPFormat(filename,startchan,endchan,seq,target,condition)
%ConvertConditionToJPFormat Convert stimulus condition to JP's format
% ConvertConditionToJPFormat(FILENAME,START_CHAN,END_CHAN,SEQ,
% TARGET,CONDITION)
% e.g. ConvertConditionToJPFormat('annie060801s03contour1.bin',
% 3,4,seq,'contour',1)
% or ConvertConditionToJPFormat('annie060801s03catch.bin',3,4,
% seq,'catch',0)
% get max duration
[duration,min_duration,trials,waves,rawfile,samplingrate] = nptReadSorterHdr(['sort' filesep '0001.hdr']);
% open binary file
fid = fopen(filename,'w','ieee-le');
if strcmp(target,'contour')
offset = (condition-1)*seq.stimsets;
elseif strcmp(target,'control')
offset = (seq.stim_steps+condition-1) * seq.stimsets;
elseif strcmp(target,'catch')
offset = 2 * seq.stim_steps * seq.stimsets;
end
% get session name
dirlist = nptDir('*.0001');
[path,filename,ext] = nptFileParts(dirlist(1).name);
% trialname = ext(2:length(ext));
% pad data if necessary
maxpoints = ceil(duration * samplingrate);
channels = endchan - startchan + 1;
for i = 1:seq.stimsets
trialname = [filename '.' num2str(seq.sequence(offset+i),'%04i')];
fprintf('Reading %s...\n',trialname);
[data,numchannels,samplingrate,scanorder,points] = nptReadStreamerFile(trialname);
padpoints = maxpoints-points;
if padpoints~=0
% pzeros = zeros(1,padpoints);
pdata = transpose([data(startchan:endchan,:) zeros(channels,padpoints)]);
else
pdata = transpose(data(startchan:endchan,:));
end
fwrite(fid,pdata,'int16');
end
fclose(fid);