-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch_plot.m
142 lines (127 loc) · 4.79 KB
/
switch_plot.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
%% Create GUI for figure selection
function [dir,blockid,fig,g,ax,d,bb,StimOffsets] = switch_plot(dir,blockid,num_p,StimOffsets)
% INPUT:
% dir; file directory
% blockid; recording block name
% num_p, number of data panels to plot
% stimOffsets; stim offset times in samples
%
% OUTPUT:
% dir; file directory
% blockid; recording block name
% fig; figure handle
% g; ui parent handle
% ax; a cell array of axes handle
% d; a cell array of uidropdown handles
% bb; ui button handle
% stimOffsets; stim offset times in samples
% generate figure
fig = uifigure('Name',blockid);
g = uigridlayout(fig);
r = [repmat("1x",1,num_p) 'fit'];
g.RowHeight = r;
g.ColumnWidth = {'fit','fit','fit','fit','fit','1x'};
d{1} = uidropdown(g,...
"Items",["","P1","P2"], ...
"ItemsData",["","P1","P2"],"Tag","Probe");
d{1}.Layout.Row = num_p+1;
d{1}.Layout.Column = 1;
d{2} = uidropdown(g,...
"Items",["" compose('Ch%03d',0:31)], ...
"ItemsData",["" compose('%03d',0:31)],"Tag","Channel");
d{2}.Layout.Row = num_p+1;
d{2}.Layout.Column = 2;
d{3} = uidropdown(g, ...
"Items",["","Raw","Artifact","Cleaned","Filtered","Spikes","Mean Rate"], ...
"ItemsData",["","raw","art","clean","filt","sp","mfr"],"Tag","Type");
d{3}.Layout.Row = num_p+1;
d{3}.Layout.Column = 3;
% load associated stimulation file
if nargin < 4
load(fullfile(dir,[blockid '_StimTimes.mat']));
end
bb = uibutton(g, ...
"Text","Generate Trial","ButtonPushedFcn",@(src,event) updateTrial(src,StimOffsets));
tot = numel(StimOffsets);
idx = randperm(tot,1);
bb.Tag = sprintf('%8.0f', StimOffsets(idx));
l = uieditfield(g,"numeric", ...
"ValueChangedFcn",@(l,event) textChanged(l,bb));
for i = 1:num_p
ax{i} = uiaxes(g);
ax{i}.Layout.Row = i;
ax{i}.Layout.Column = [2 6];
ax{i}.Title.String = bb.Tag;
ax{i}.TitleHorizontalAlignment = 'left';
b{i} = uibutton(g,"Text","Plot","ButtonPushedFcn",@(src,event) updatePlot(dir,blockid,ax{i},d,bb));
b{i}.Layout.Row = i;
b{i}.Layout.Column = 1;
b{i}.HorizontalAlignment = 'center';
end
end
function updatePlot(dir,blockid,ax,d,bb)
probe = char(d{1}.Value);
channel = char(d{2}.Value);
type = d{3}.Value;
stim_trial = str2num(bb.Tag);
switch type
case 'raw'
ff = fullfile(dir,[blockid '_RawData'],[blockid '_Raw_' probe '_Ch_' channel]);
load(ff,"data");
% data(stim_trial:stim_trial+15) = 0; % just helps for scaling
plot(ax,linspace(0,10,301),data(stim_trial:stim_trial+300),"Color","#000");
ax.Title.String = sprintf('%8.0f', stim_trial);
ax.XLim = [0 10];
case 'art'
load(fullfile(dir,[blockid '_RawData'],[blockid '_Raw_' probe '_Ch_' channel]),'data');
raw = data;
load(fullfile(dir,[blockid '_RawData_StimSmoothed'],[blockid '_Raw_StimSmoothed_' probe '_Ch_' channel]),'data');
clean = data;
data = raw - clean;
plot(ax,linspace(0,10,301),data(stim_trial:stim_trial+300),"Color","#000");
ax.Title.String = sprintf('%8.0f', stim_trial);
ax.XLim = [0 10];
case 'clean'
ff = fullfile(dir,[blockid '_RawData_StimSmoothed'],[blockid '_Raw_StimSmoothed_' probe '_Ch_' channel]);
load(ff,"data");
plot(ax,linspace(0,10,301),data(stim_trial:stim_trial+300),"Color","#000");
ax.Title.String = sprintf('%8.0f', stim_trial);
ax.XLim = [0 10];
case 'filt'
ff = fullfile(dir,[blockid '_Filtered_StimSmoothed'],[blockid '_Filt_' probe '_Ch_' channel]);
load(ff,"data");
plot(ax,linspace(0,10,301),data(stim_trial:stim_trial+300),"Color","#000");
ax.Title.String = sprintf('%8.0f', stim_trial);
ax.XLim = [0 10];
case 'sp'
ff = fullfile(dir,[blockid '_SD_SWTTEO'],[blockid '_ptrain_' probe '_Ch_' channel]);
load(ff,"peak_train");
output = peak_train;
output = find(output(stim_trial:stim_trial+300));
cla(ax);
if output > 0
xline(ax,output,"Color","#000");
end
ax.Title.String = sprintf('%8.0f', stim_trial);
ax.XLim = [0 300];
ax.XTick = linspace(0,300,11);
ax.XTickLabel = 0:10;
case 'mfr'
ff = fullfile(dir,[blockid '_stats_swtteo']);
load(ff,"chPlot");
chan = compose('Ch_%s',channel);
idxPl = find(strcmp(string(chPlot.arr),probe) & strcmp(string(chPlot.ch),chan));
output = chPlot.mean_evoked_rate{idxPl};
plot(ax,linspace(0,10,101),output,"Color","#000");
ax.Title.String = sprintf('%8.0f', stim_trial);
ax.XLim = [0 10];
end
end
function updateTrial(src,StimOffsets)
tot = numel(StimOffsets);
idx = randperm(tot,1);
src.Tag = string(StimOffsets(idx));
end
function textChanged(l,bb)
bb.Tag = string(l.Value);
end