-
Notifications
You must be signed in to change notification settings - Fork 0
/
Online_NidaqPlot.m
100 lines (87 loc) · 3.12 KB
/
Online_NidaqPlot.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
function figData=Online_NidaqPlot(action,phototitle,figData,newData470,nidaqRaw,plotidx)
global BpodSystem TaskParameters
%% general ploting parameters
labelx='Time (sec)'; labely='DF/F';
minx=TaskParameters.GUI.TimeMin; maxx=TaskParameters.GUI.TimeMax; xstep=1; xtickvalues=minx:xstep:maxx;
miny=TaskParameters.GUI.NidaqMin; maxy=TaskParameters.GUI.NidaqMax;
MeanThickness=2;
switch action
case 'ini'
%% Close pre-existing plot and test parameters
figtitle=sprintf('Photometry %s',phototitle);
try
close(figtitle)
end
%% Create Figure
ScrSze=get(0,'ScreenSize');
FigSze=[ScrSze(3)*1/3 ScrSze(2)+40 ScrSze(3)*1/3 ScrSze(4)-120];
figPlot=figure('Name',figtitle,'Position',FigSze, 'numbertitle','off');
hold on
% ProtoSummary=sprintf('%s : %s -- %s - %s',...
% date, BpodSystem.GUIData.SubjectName, ...
% BpodSystem.GUIData.ProtocolName, TaskParameters.Names.Phase{TaskParameters.GUI.Phase});
ProtoLegend=uicontrol('style','text');
% set(ProtoLegend,'String',ProtoSummary);
set(ProtoLegend,'Position',[10,1,400,20]);
%% Current Nidaq plot
lastsubplot=subplot(4,2,[1 2]);
hold on
title('Nidaq recording');
xlabel(labelx); ylabel('Voltage');
ylim auto;
set(lastsubplot,'XLim',[minx maxx],'XTick',xtickvalues);%'YLim',[miny maxy]
lastplotRaw=plot([-5 5],[0 0],'-k');
lastplot470=plot([-5 5],[0 0],'-g','LineWidth',MeanThickness);
hold off
%% Plot previous recordings
subplotTitles={'all choice','leave','reward'};
for i=1:3
subplotTitles{i}=sprintf('%s',subplotTitles{i});
end
%Subplot
for i=1:3
photosubplot(i)=subplot(4,2,i+2);
hold on
title(subplotTitles(i));
xlabel(labelx); ylabel(labely);
ylim auto;
set(photosubplot(i),'XLim',[minx maxx],'XTick',xtickvalues,'YLim',[miny maxy]);
rewplot(i)=plot([0 0],[-1,1],'-b');
meanplot(i)=plot([-5 5],[0 0],'-r');
hold off
end
set(photosubplot(1),'XLabel',[]);
% set(photosubplot(2),'XLabel',[],'YLabel',[]);
% set(photosubplot(3),'XLabel',[]);
% set(photosubplot(4),'XLabel',[],'YLabel',[])
%set(photosubplot(5),'XLabel',labelx,'YLabel',labely);
% set(photosubplot(6),'YLabel',[]);
%Save the figure properties
figData.fig=figPlot;
figData.lastsubplot=lastsubplot;
figData.lastplotRaw=lastplotRaw;
figData.lastplot470=lastplot470;
figData.photosubplot=photosubplot;
figData.meanplot=meanplot;
case 'update'
%% Update last recording plot
set(figData.lastplotRaw, 'Xdata',nidaqRaw(:,1),'YData',nidaqRaw(:,2));
set(figData.lastplot470, 'Xdata',newData470(:,1),'YData',newData470(:,2));
%% Compute new average trace
allData=get(figData.photosubplot(plotidx), 'UserData');
dataSize=size(allData,2);
allData(:,dataSize+1)=newData470(:,3);
set(figData.photosubplot(plotidx), 'UserData', allData);
meanData=mean(allData,2);
curSubplot=figData.photosubplot(plotidx);
set(figData.meanplot(plotidx), 'Xdata',newData470(:,1),'YData',meanData,'LineWidth',MeanThickness);
set(curSubplot,'NextPlot','add');
plot(newData470(:,1),newData470(:,3),'-k','parent',curSubplot);
uistack(figData.meanplot(plotidx), 'top');
hold off
%% Update GUI plot parameters
for i=1:3
set(figData.photosubplot(i),'XLim',[minx maxx],'XTick',xtickvalues,'YLim',[miny maxy])
end
end
end