@@ -4,12 +4,6 @@ function plotUnits(app)
44 % app.Data.modifyList. We should only update those axes!
55 app.Data.loader = uiprogressdlg(app .UIFigure ,' Title' ,' Please Wait' ,...
66 ' Message' ,' Loading clusters' );
7- % Delete all previous spike panels
8- ch = app .UnitsPanel .Children ;
9- for c = 1 : length(ch )
10- delete(ch );
11- app.SpikePanels = [];
12- end
137
148 app.RecalcButton.Position = [app .TabMerge .Position(3 )-450 app .TabMerge .Position(4 )-30 145 24 ];
159 app.AggCutoff.Position = app .RecalcButton .Position + [-120 0 - 30 0 ];
@@ -49,64 +43,74 @@ function plotUnits(app)
4943
5044 app.SelectedUnits.Items = {' Loading...' };
5145
46+ temp = cellfun(@isempty ,app .SpikePanels );
47+ currentlyPlotted = find(~temp );
48+ clear temp
49+ toDrop = setdiff(currentlyPlotted ,unq ); % remove panels that aren't in there
50+ for t = 1 : length(toDrop )
51+ delete(app.SpikePanels{toDrop(t )});
52+ app.SpikePanels{toDrop(t )} = [];
53+ end
54+
5255 yl = NaN(2 ,length(unq )); % for scaling if app.Settings.ToScale == true
5356 for u = 1 : length(unq )
57+ % if it doesn't have an axes plotted for it:
58+ if length(app .SpikePanels ) < unq(u ) || isempty(app.SpikePanels{unq(u )})
59+ app.SpikePanels{unq(u )} = uiaxes(app .UnitsPanel );
60+ % a bit redundant, but may allow for compressing cell array later:
61+ % (can't at present if a new unit appears with a lower UID than an old one)
62+ app.SpikePanels{unq(u )}.UserData.UID = unq(u );
63+ app.Data.modifyList = [app .Data .modifyList unq(u )];
64+ end
65+
5466 app.Data.loader.Message = [' Loading unit ' num2str(u ) ' of ' num2str(length(unq ))];
5567
5668 xpos = mod(u - 1 ,4 );
5769 ypos = floor((u - 1 )/4 );
58-
59- app.SpikePanels{u } = uiaxes(app .UnitsPanel );
60- app.SpikePanels{u }.Position = [margin +(xpos * w ) (start_y -(ypos * w ))-max_y w w ];
61-
62- t = (0 : size(app .Data .spikes .waveforms ,2 )-1 )/(app .Data .spikes .params .Fs / 1e3 );
63- t = t - app .Data .spikes .params .cross_time ;
64-
65- ids = app .Data .spikes .assigns == unq(u );
66- waveforms = app .Data .spikes .waveforms(ids ,: );
67- [tt ,wvs ] = compressSpikes(app ,t ,waveforms );
68-
69- if app .Settings .Colorful
70- line(app.SpikePanels{u },tt ,wvs ,' Color' ,app .Data .colors(u ,: ));
71- else
72- line(app.SpikePanels{u },tt ,wvs );
73- end
74-
75- rpv = sum(diff(app .Data .spikes .spiketimes(ids )) <= (app .Data .spikes .params .refractory_period * 0.001 ));
76- plural = ' ' ;
77- if rpv ~= 1 , plural = ' s' ; end
78- if rpv / length(app .Data .spikes .spiketimes(ids )) > 0.02
79- rpvCol = ' red' ;
80- else
81- rpvCol = ' gray' ;
70+ app.SpikePanels{unq(u )}.Position = [margin +(xpos * w ) (start_y -(ypos * w ))-max_y w w ];
71+ if any(ismember(app .Data .modifyList ,unq(u )))
72+ cla(app.SpikePanels{unq(u )});
73+ t = (0 : size(app .Data .spikes .waveforms ,2 )-1 )/(app .Data .spikes .params .Fs / 1e3 );
74+ t = t - app .Data .spikes .params .cross_time ;
75+
76+ ids = app .Data .spikes .assigns == unq(u );
77+ waveforms = app .Data .spikes .waveforms(ids ,: );
78+ [tt ,wvs ] = compressSpikes(app ,t ,waveforms );
79+
80+ if app .Settings .Colorful
81+ line(app.SpikePanels{unq(u )},tt ,wvs ,' Color' ,app .Data .colors(u ,: ));
82+ else
83+ line(app.SpikePanels{unq(u )},tt ,wvs );
84+ end
85+
86+ rpv = sum(diff(app .Data .spikes .spiketimes(ids )) <= (app .Data .spikes .params .refractory_period * 0.001 ));
87+ plural = ' ' ;
88+ if rpv ~= 1 , plural = ' s' ; end
89+ if rpv / length(app .Data .spikes .spiketimes(ids )) > 0.02
90+ rpvCol = ' red' ;
91+ else
92+ rpvCol = ' gray' ;
93+ end
94+
95+ label = app .Data .spikes .labels(app .Data .spikes .labels(: ,1 ) == unq(u ),2 );
96+ if label == 2
97+ labelCol = ' 0 0.6 0.2' ;
98+ else
99+ labelCol = ' 0 0 0' ;
100+ end
101+ app.SpikePanels{unq(u )}.Title.String = [' {\color[rgb]{' labelCol ' }Unit ' num2str(unq(u )) ' }: n = ' num2str(size(waveforms ,1 )) ' {\color{' rpvCol ' }(' num2str(rpv ) ' RPV' plural ' )}' ];
102+
103+ disableDefaultInteractivity(app.SpikePanels{unq(u )});
104+ app.SpikePanels{unq(u )}.XGrid = ' on' ;
105+ app.SpikePanels{unq(u )}.YGrid = ' on' ;
106+ if isfield(app.SpikePanels{unq(u )},' Toolbar' )
107+ app.SpikePanels{unq(u )}.Toolbar.Visible = ' off' ;
108+ end
109+
110+ xlim(app.SpikePanels{unq(u )},[t(1 ) t(end )]);
82111 end
83-
84- label = app .Data .spikes .labels(app .Data .spikes .labels(: ,1 ) == unq(u ),2 );
85- if label == 2
86- labelCol = ' 0 0.6 0.2' ;
87- else
88- labelCol = ' 0 0 0' ;
89- end
90- app.SpikePanels{u }.Title.String = [' {\color[rgb]{' labelCol ' }Unit ' num2str(unq(u )) ' }: n = ' num2str(size(waveforms ,1 )) ' {\color{' rpvCol ' }(' num2str(rpv ) ' RPV' plural ' )}' ];
91-
92- disableDefaultInteractivity(app.SpikePanels{u });
93- app.SpikePanels{u }.XGrid = ' on' ;
94- app.SpikePanels{u }.YGrid = ' on' ;
95- if isfield(app.SpikePanels{u },' Toolbar' )
96- app.SpikePanels{u }.Toolbar.Visible = ' off' ;
97- end
98-
99- % app.SpikePanels{u}.ButtonDownFcn = createCallbackFcn(app, @UnitClick, true);
100-
101- %{
102- app.SpikePanels{u}.XColor = 'none';
103- yl = ylim(app.SpikePanels{u});
104- text(app.SpikePanels{u},-0.6, yl(1), [num2str(yl(1)) '�V']);
105- text(app.SpikePanels{u},-0.6, yl(2), [num2str(yl(2)) '�V']);
106- %}
107- xlim(app.SpikePanels{u },[t(1 ) t(end )]);
108-
109- yl(: ,u ) = ylim(app.SpikePanels{u });
112+ % TODO: need to have a handle to the line for each panel, and update its color if needed here
113+ yl(: ,u ) = ylim(app.SpikePanels{unq(u )});
110114
111115 app.SelectedUnits.Items{u } = [' Unit ' num2str(unq(u ))];
112116
@@ -124,10 +128,18 @@ function plotUnits(app)
124128 % link the axes, and apply the largest ylim
125129 % linkaxes(app.SpikePanels,'y'); linkaxes doesn't work with UIAxes objects in r2018b...
126130 for u = 1 : length(unq )
127- set(app.SpikePanels{u },' YLim' ,[min(yl(: )) max(yl(: ))])
131+ set(app.SpikePanels{unq( u ) },' YLim' ,[min(yl(: )) max(yl(: ))])
128132 end
129133 end
130-
134+ %{
135+ if app.Settings.Colorful
136+ for u = 1:length(unq)
137+ app.SpikePanels{unq(u)}.Children(1).Color = app.Data.colors(u,:);
138+ else
139+ app.SpikePanels{unq(u)}.Children(1).Color = [0 0.4470 0.7410];
140+ end
141+ end
142+ %}
131143 app .Data .modified(1 ) = 0 ;
132144 app .Data .doFirstPlot(1 ) = 0 ;
133145 app.Data.modifyList = [];
0 commit comments