📄 eeg_crosshair.m
字号:
set(H.gui,'userdata',H);
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [H] = viewpeaks(H)
view = get(H.handles.peaksView,'Value');
if ~view,
% switch off any current peak handles from plot
if isfield(H.handles,'peakhandles'),
h = H.handles.peakhandles;
if ishandle(h(1)), delete(h); end
end
return;
end
% Make sure data required for peaks is available
H = checkpeaks(H);
% delete any current peak handles from plot
if isfield(H.handles,'peakhandles'),
h = H.handles.peakhandles;
if ishandle(h(1)), delete(h); end
end
elec = H.data.yindex;
peaksindex = find(H.p.volt.peaks.data(:,elec) ~= 0);
time = H.p.volt.timeArray(peaksindex,elec);
volt = H.p.volt.data(peaksindex,elec);
figure(H.gui);
hold on;
H.handles.peakhandles = scatter(time,volt);
hold off;
%if view,
% set(H.handles.peakhandles,'Visible','on');
%else
% set(H.handles.peakhandles,'Visible','off');
%end
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [H] = movepeak(H,move)
% Make sure data required for peaks is available
H = checkpeaks(H);
elec = H.data.yindex;
peaksindex = find(H.p.volt.peaks.data(:,elec) ~= 0);
time = H.p.volt.timeArray(peaksindex,elec);
volt = H.p.volt.data(peaksindex,elec);
% Find nearest peakindex to currentpoint
x = H.data.xpoint;
peaks = [time volt];
nindex = 1; pindex = 1;
for i=1:length(peaks),
peak = peaks(i,:);
if (x > peak(1)),
pindex = i;
if (i+1 <= length(peaks)), nindex = i+1;
else nindex = i;
end
elseif (x == peak(1)),
pindex = i-1;
if (i-1 > 0), pindex = i-1;
else pindex = 1;
end
if (i+1 <= length(peaks)), nindex = i+1;
else nindex = i;
end
end
end
% Identify prev/next peak
if strcmp(move,'nextpeak'), index = nindex;
else index = pindex;
end
H.data.xpoint = time(index);
H.data.ypoint = volt(index);
xdata = H.data.xdata(:,H.data.yindex);
H.data.xindex = NearestXYArrayPoint( xdata, H.data.xpoint, 'exact' );
set(H.handles.interp,'Value',1);
H = updateGUI(H);
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [H] = checkpeaks(H)
% Make sure peaks data required is available
if isfield(H,'p'),
if isfield(H.p.volt,'peaks'),
if isempty(H.p.volt.peaks),
H.p.volt.timeArray = H.data.xdata;
H.p.volt.data = H.data.ydata;
H.p = eeg_peaks(H.p);
end
else
H.p.volt.timeArray = H.data.xdata;
H.p.volt.data = H.data.ydata;
H.p = eeg_peaks(H.p);
end
else
H.p.volt.timeArray = H.data.xdata;
H.p.volt.data = H.data.ydata;
H.p = eeg_peaks(H.p);
end
% Check the volt.timeArray
if isempty(H.p.volt.timeArray),
H.p.volt.timeArray = H.data.xdata;
end
if ~isequal(size(H.p.volt.timeArray),size(H.p.volt.data)),
H.p.volt.timeArray = repmat(H.p.volt.timeArray,1,size(H.p.volt.data,2));
end
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [H] = moveXY(H,move)
interp = get(H.handles.interp,'Value');
xinterp = get(H.handles.xinterp,'Value');
if (xinterp > 0) & (interp > 1),
% Use incremental interpolation of x values
switch move,
case 'nexty', H.data.yindex = H.data.yindex + 1;
case 'prevy', H.data.yindex = H.data.yindex - 1;
case 'ygt',
ydata = interpYall(H);
[ysort,yi] = sort(ydata);
currYI = find(ysort > H.data.ypoint);
if min(currYI),
H.data.yindex = yi(min(currYI));
end
case 'ylt',
ydata = interpYall(H);
[ysort,yi] = sort(ydata);
currYI = find(ysort < H.data.ypoint);
if max(currYI),
H.data.yindex = yi(max(currYI));
end
case 'nextx',
H.data.xpoint = H.data.xpoint + xinterp;
case 'prevx',
H.data.xpoint = H.data.xpoint - xinterp;
end
H = checkdatarange(H);
H = interpY(H);
updateGUI(H);
return
end
% No interpolation of x values...
if (interp > 1)
xdata = H.data.xdata(:,H.data.yindex);
[H.data.xindex] = NearestXYArrayPoint( xdata, H.data.xpoint, move );
end
switch move,
case 'nextx',
% Increase current xindex by one
if(interp == 1), H.data.xindex = H.data.xindex + 1; end
case 'prevx',
% Decrease current xindex by one
if(interp == 1), H.data.xindex = H.data.xindex - 1; end
case 'nexty', H.data.yindex = H.data.yindex + 1;
case 'prevy', H.data.yindex = H.data.yindex - 1;
case 'ygt',
ydata = H.data.ydata(H.data.xindex,:);
[ysort,yi] = sort(ydata);
currYI = find(ysort == H.data.ypoint);
if currYI < length(yi),
H.data.yindex = yi(currYI+1);
end
case 'ylt',
ydata = H.data.ydata(H.data.xindex,:);
[ysort,yi] = sort(ydata);
currYI = find(ysort == H.data.ypoint);
if currYI > 1,
H.data.yindex = yi(currYI-1);
end
otherwise
end
% Ensure that x/y index is within data range
H = checkdatarange(H);
% Get x/y value at new x/y index
H.data.xpoint = H.data.xdata(H.data.xindex,H.data.yindex);
H.data.ypoint = H.data.ydata(H.data.xindex,H.data.yindex);
set(H.handles.interp,'Value',1);
H = updateGUI(H);
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ H ] = checkdatarange(H),
% Ensure that x/y index is within data range
s = size(H.data.xdata,1);
if( H.data.xindex < 1 ),
H.data.xindex = 1;
elseif( H.data.xindex >= s ),
H.data.xindex = s;
end
s = size(H.data.ydata,2);
if( H.data.yindex < 1 ),
H.data.yindex = 1;
elseif( H.data.yindex >= s ),
H.data.yindex = s;
end
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ H ] = updateDATA( H )
% Only update if mouse pointer is in the
% axis limits
set(H.gui,'units','normalized');
axpos = get(H.handles.axis,'position');
figcp = get(H.gui,'Currentpoint');
axlim = axpos(1) + axpos(3);
aylim = axpos(2) + axpos(4);
if or(figcp(1) > (axlim+.01),figcp(1) < (axpos(1)-.01)),
return;
elseif or(figcp(2) > (aylim+.01),figcp(2) < (axpos(2)-.01)),
return;
end
% OK, update...
CurrentPoint = get(H.handles.axis,'Currentpoint');
H.data.xpoint = CurrentPoint(1,1);
H.data.ypoint = CurrentPoint(1,2);
doNearTrace = get(H.handles.traceNearest,'Value');
if (doNearTrace > 0)
% Get new yindex for nearest trace
[ H.data.xpoint, ...
H.data.xindex, ...
H.data.ypoint, ...
H.data.yindex ] = NearestXYMatrixPoint( H.data.xdata,...
H.data.ydata,...
H.data.xpoint,...
H.data.ypoint);
% else
% H.data.yindex = get(H.handles.trace,'Value');
end
CurrentPoint = get(H.handles.axis,'Currentpoint');
H.data.xpoint = CurrentPoint(1,1);
H.data.ypoint = CurrentPoint(1,2);
H = interpY(H);
H = updateGUI(H);
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ H ] = interpY( H )
% In this function, xdata & ydata are arrays, not matrices
xdata = H.data.xdata(:,H.data.yindex);
ydata = H.data.ydata(:,H.data.yindex);
if H.data.xpoint >= max(xdata)
H.data.xpoint = max(xdata);
H.data.xindex = find(xdata == max(xdata));
H.data.ypoint = ydata(H.data.xindex);
return;
elseif H.data.xpoint <= min(xdata)
H.data.xpoint = min(xdata);
H.data.xindex = find(xdata == min(xdata));
H.data.ypoint = ydata(H.data.xindex);
return;
end
% 'none|nearest|linear|spline|cubic'
interp = get(H.handles.interp,'Value');
switch interp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -