Skip to content

Instantly share code, notes, and snippets.

@jonbrennecke
Created July 21, 2014 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonbrennecke/8ec011625a3833563175 to your computer and use it in GitHub Desktop.
Save jonbrennecke/8ec011625a3833563175 to your computer and use it in GitHub Desktop.
function [data]= unitactivity(chanNum,sort,snippetWidth,snippetOffset,tank,block,data)
%chanNum = channel number from which to draw data;
%sort = cluster of units to be plotted in parallel with the EEG. Can be any subset of sort codes for that channel or all of them
%snippetWidth = number of seconds of data to plot
%snippetOffset= number of seconds into the file to start plotting.
%tank and block are the data source. For instance: 'D:\OptoTagging\6_16_14','6_16_14_10min_Stim'
%
%data = an optional parameter. If a TDT block data set already exists as a structured array, the
%function will plot data from that structured array. If the data structure
%does not yet exist, DO NOT list data as a a parameter. ONLY input the
%first 6 parameters. This function will generate data from the specified
%tank and block and plot the resulting data.
if ~exist('data','var')
data = TDT2mat(tank,block);
end
if ~exist('sort','var')
sort = 1:3;
end
eNeu = data.snips.eNeu;
EEGx = data.streams.EEGx;
for i=1:length(sort)
chansort{i} = eNeu.ts(intersect(find(eNeu.chan==chanNum),find(eNeu.sortcode==sort(i))));
end
if snippetOffset < 1/EEGx.fs
snippetOffset = 1/EEGx.fs;
end
figure
set(gca,'Color','black');
hold on
window = round(EEGx.fs * snippetOffset):round(EEGx.fs * snippetOffset + EEGx.fs * snippetWidth);
plot((window/EEGx.fs),EEGx.data(chanNum,window),'w')
a = [snippetOffset (snippetOffset + snippetWidth) (-max(EEGx.data(window))*1.5) max(EEGx.data(window))];
axis(a)
title(['EEG Signal in channel ' num2str(chanNum) ])
% plot sortcodes
colors = {'r.','m.','g.'};
for i=1:length(sort)
snipEvents = chansort{:,i}(chansort{:,i} > snippetOffset & chansort{:,i} < snippetOffset + snippetWidth);
% subplot(length(sort)+1,1,i+1);
plot(snipEvents,ones(length(snipEvents)).*a(3)+(abs(a(3)-a(4))*0.05*i),colors{i})
axis(a)
title(['Sort Code ' num2str(i)])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment