📄 viewedf.m
字号:
Opt.ButHeight = Opt.TxtHeight * 1.2;
Opt.ValidHeight = 0.005;
Opt.FigX = Data.Display.DrawRect(1);
Opt.FigWidth = Data.Display.DrawRect(3);
if Data.ShowRange
Opt.LabelWidth = min([0.1, 4*LocalGetFontWidth]);
else
Opt.LabelWidth = 0;
end
Opt.FigY = Data.Display.DrawRect(2) + Data.Display.DrawRect(4) - ...
1.5*Opt.TxtHeight - Opt.ValidHeight;
Opt.FigHeight = (Data.Display.DrawRect(4) - 1.5*Opt.TxtHeight - ...
Opt.ValidHeight) / TotPlots - Opt.YSpace;
Opt.TxtHeight = min([(Opt.FigHeight-Opt.YSpace)/2, Opt.TxtHeight]);
Opt.ButHeight = min([(Opt.FigHeight-Opt.YSpace)/2, Opt.ButHeight]);
Opt.XPixels = 4*xpix;
Opt.ShowRange = Data.ShowRange;
% clear old buttons and labels
if ~KeepOldPlots & ~isempty(Data.Display.Axes)
delete(Data.Display.HScrollBar);
if ~isempty(Data.Display.Cursor);
delete(Data.Display.Cursor.Line(:));
delete(Data.Display.Cursor.Menu.Text);
delete(Data.Display.Cursor.Menu.Menu);
Data.Display.Cursor = [];
end
delete(Data.Display.Axes(:).RecButton);
delete(Data.Display.Axes(:).ScaleUpButton);
delete(Data.Display.Axes(:).ScaleDownButton);
delete(Data.Display.Axes(:).RecLabel);
delete(Data.Display.Axes(:).MaxLabel);
delete(Data.Display.Axes(:).MinLabel);
delete(Data.Display.Axes(:).DimLabel);
delete(Data.Display.Axes(:).PlotLine);
delete(Data.Display.Axes(:).Plot);
Data.Display.Axes = [];
end
% draw HScrollBar
FileDur = LocalGetEDFInfo('FileDur',Data.EDF);
[MaxVal, MFInd] = max(FileDur);
Dur = LocalGetEDFInfo('Dur', Data.EDF);
[MaxDur, MDInd] = max(Dur);
Len = Data.Display.EDF(MFInd).ShowRecords(1);
if ~KeepOldPlots
Data.Display.HScrollBar = uicontrol(gcf, ...
'Style', 'Slider', ...
'Units', 'Normalized', ...
'Position', [Data.Display.DrawRect(1), 0, ...
Data.Display.DrawRect(3), LocalGetFontHeight], ...
'SliderStep', [MaxDur/MaxVal 5*MaxDur/MaxVal] * ...
Data.Display.EDF(MDInd).ShowRecords(2), ...
'Min', 0, ...
'Max', 1, ...
'Value', Data.Display.EDF(MFInd).ShowRecords(1)/MaxVal*Dur(MFInd), ...
'CallBack', 'viewedf HScroll');
else
set(Data.Display.HScrollBar, ...
'Value', Data.Display.EDF(MFInd).ShowRecords(1)/MaxVal*Dur(MFInd));
end
%create new buttons, plots and labels
cnt = 0;
for j=1:length(Data.EDF)
for i=1:length(Data.Display.EDF(j).ShowSignals)
cnt = cnt+1;
showsig = Data.Display.EDF(j).ShowSignals(i);
if ~KeepOldPlots
% make new plots, buttons, labels
Opt.YPos = Opt.FigY - Opt.YSpace*(cnt-1) - Opt.FigHeight * cnt;
Opt.DisplayMin = Data.Display.EDF(j).DisplayMin(showsig);
Opt.DisplayMax = Data.Display.EDF(j).DisplayMax(showsig);
Opt.UserData = { 'EDF', showsig, j};
Opt.Label = Data.EDF(j).Head.Label(showsig,:);
Opt.YLabel = deblank(Data.EDF(j).Head.PhysDim(showsig,:));
yd = Data.EDF(j).Record{showsig};
if (length(yd) ~= 1)
yd = [yd(:); NaN];
end
Temp = ...
LocalPlotNewData(yd, ...
Data.Display.EDF(j).UpDownPlot(showsig), ...
Data.Display.EDF(j).StairPlot(showsig), Opt);
if cnt == 1
Data.Display.Axes = Temp;
else
Data.Display.Axes(cnt) = Temp;
end
else
% set new ydata
yd = Data.EDF(j).Record{showsig} * ...
(Data.Display.EDF(j).UpDownPlot(showsig)-0.5) * -2;
if (length(yd) == 1)
yd = yd([1 1]);
else
yd = yd(1:ceil(length(yd)/Opt.XPixels):length(yd));
yd = [yd(:); NaN];
if Data.Display.EDF(j).StairPlot(showsig)
yd = yd(floor(1:0.5:length(yd)));
end
end
set(Data.Display.Axes(cnt).PlotLine, 'YData', yd);
end
end
end
% plot plugin-data
for j = 1:length(Data.Plugin)
for i=1:length(Data.Display.Plugin(j).ShowSignals)
cnt = cnt+1;
showsig = Data.Display.Plugin(j).ShowSignals(i);
if ~KeepOldPlots
% make new plots, buttons, labels
Opt.YPos = Opt.FigY - Opt.YSpace*(cnt-1) - Opt.FigHeight * cnt;
Opt.DisplayMin = Data.Display.Plugin(j).DisplayMin(showsig);
Opt.DisplayMax = Data.Display.Plugin(j).DisplayMax(showsig);
Opt.UserData = { 'PLUGIN', showsig, j};
Opt.Label = Data.Plugin(j).EDF.Head.Label(showsig,:);
Opt.YLabel = deblank(Data.Plugin(j).EDF.Head.PhysDim(showsig,:));
yd = Data.Plugin(j).EDF.Record{showsig};
if (length(yd) ~= 1)
yd = [yd(:); NaN];
end
Data.Display.Axes(cnt) = ...
LocalPlotNewData(yd, ...
Data.Display.Plugin(j).UpDownPlot(showsig), ...
Data.Display.Plugin(j).StairPlot(showsig), Opt);
else
yd = Data.Plugin(j).EDF.Record{showsig} * ...
(Data.Display.Plugin(j).UpDownPlot(showsig)-0.5) * -2;
if (length(yd) == 1)
yd = yd([1 1]);
else
yd = yd(1:ceil(length(yd)/Opt.XPixels):length(yd));
yd = [yd(:); NaN];
if Data.Display.Plugin(j).StairPlot(showsig)
yd = yd(floor(1:0.5:length(yd)));
end
end
set(Data.Display.Axes(cnt).PlotLine, 'YData', yd);
end
end
end
% change size of all strings
set(Data.Display.Strings.CurrTime, ...
'Position', [Opt.TextX, 0, Opt.TextWidth, fhght]);
pos = get(Data.Display.Strings.TotTime, 'Position');
set(Data.Display.Strings.TotTime, ...
'Position', [pos(1), 1 - 1.25 * fhght, pos(3), fhght]);
pos = get(Data.Display.Strings.DispTime, 'Position');
set(Data.Display.Strings.DispTime, ...
'Position', [pos(1), 1 - 1.25 * fhght, pos(3), fhght]);
pos = get(Data.Display.Strings.FileName, 'Position');
ext = get(Data.Display.Strings.FileName, 'Extent');
set(Data.Display.Strings.FileName, ...
'Position', [pos(1), 1 - 1.25 * fhght, ext(3) + 0.01, fhght]);
% change size of HScrollBar
pos = get(Data.Display.HScrollBar, 'Position');
set(Data.Display.HScrollBar, ...
'Position', [pos(1) pos(2) pos(3) fhght]);
% draw cursor
if Data.ShowCursor & ~KeepOldPlots
Data.Display.Cursor = LocalDrawCursor(Data.Display);
end
% display time
tsec = Data.EDF(1).Head.Dur * Data.Display.EDF(1).ShowRecords(1);
tmin = floor(tsec/60);
tsec = rem(tsec,60);
th = floor(tmin/60);
tmin = rem(tmin,60);
set(Data.Display.Strings.CurrTime, 'String', ...
sprintf('Time %02d:%02d:%02d', th,tmin,tsec));
tsec = Data.EDF(1).Head.Dur * Data.Display.EDF(1).ShowRecords(2);
tmin = floor(tsec/60);
tsec = rem(tsec,60);
th = floor(tmin/60);
tmin = rem(tmin,60);
set(Data.Display.Strings.DispTime, 'String', ...
sprintf('Displayed : %02d:%02d:%02d', th,tmin,tsec));
set(gcf, 'UserData', Data);
drawnow;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LocalPlotNewData
% plots a single data vector
function [ploth] = LocalPlotNewData(Data, UpDownPlot, StairPlot, Opt)
len = length(Data);
ploth.Plot = subplot('Position', ...
[Opt.FigX + Opt.LabelWidth, Opt.YPos, Opt.FigWidth - Opt.LabelWidth, ...
Opt.FigHeight - Opt.YSpace]);
if (len == 1)
xd = [1 2];
yd = Data([1 1]);
else
yd = Data(1:ceil(len/Opt.XPixels):len);
len = length(yd);
if StairPlot
xd = ceil(1:0.5:len);
yd = yd(floor(1:0.5:len));
else
xd = 1:len;
end
end
if UpDownPlot
yd = yd * -1;
tmp = Opt.DisplayMin;
Opt.DisplayMin = -Opt.DisplayMax;
Opt.DisplayMax = -tmp;
end
ploth.PlotLine = plot(xd, yd);
set(gca, ...
'XLim', [1 max([2, len])], ...
'YLim', [Opt.DisplayMin Opt.DisplayMax]);
if ~Opt.ShowRange
set(gca, ...
'XTickLabel', '', ...
'YTickLabel', '', ...
'XTick', [], ...
'YTick', []);
ploth.MaxLabel = [];
ploth.MinLabel = [];
ploth.DimLabel = [];
else
% get TickLabels used by MatLab
set(gca, ...
'YTick', [Opt.DisplayMin Opt.DisplayMax]);
labelstr = get(gca, 'YTickLabel');
labelstr = {deblank(labelstr(1,:)) deblank(labelstr(2,:))};
if UpDownPlot
for i=1:2
if labelstr{i}(1) == '-'
labelstr{i} = labelstr{i}(2:length(labelstr{i}));
else
labelstr{i} = ['-' labelstr{i}];
end
end
end
set(gca, 'YTickLabel', '');
% place TickLabels
ploth.MinLabel = text(0, 0, ...
labelstr{1}, ...
'Parent', gca, ...
'HorizontalAlignment', 'right', ...
'VerticalAlignment', 'baseline', ...
'Units', 'normalized');
ploth.MaxLabel = text(0, 1, ...
labelstr{2}, ...
'Parent', gca, ...
'HorizontalAlignment', 'right', ...
'VerticalAlignment', 'cap', ...
'Units', 'normalized');
% place physical dimension
ploth.DimLabel = text(0, 0.5, ...
['[' Opt.YLabel ']'], ...
'Parent', gca, ...
'HorizontalAlignment', 'right', ...
'VerticalAlignment', 'middle', ...
'Units', 'normalized');
end
ButWidth = Opt.TextWidth / 3;
ploth.RecButton = uicontrol(gcf, ...
'Style', 'PushButton', ...
'Units', 'Normalized', ...
'String', '?', ...
'Position', [Opt.TextX, Opt.YPos, ButWidth, Opt.ButHeight], ...
'Callback', 'viewedf RecordProp', ...
'UserData', Opt.UserData);
ploth.ScaleUpButton = uicontrol(gcf, ...
'Style', 'PushButton', ...
'Units', 'Normalized', ...
'String', '+', ...
'Position', [Opt.TextX+ButWidth, Opt.YPos, ButWidth, Opt.ButHeight], ...
'Callback', 'viewedf ScaleUp', ...
'UserData', Opt.UserData);
ploth.ScaleDownButton = uicontrol(gcf, ...
'Style', 'PushButton', ...
'Units', 'Normalized', ...
'String', '-', ...
'Position', [Opt.TextX+2*ButWidth, Opt.YPos, ButWidth, Opt.ButHeight], ...
'Callback', 'viewedf ScaleDown', ...
'UserData', Opt.UserData);
ploth.RecLabel = uicontrol(gcf, ...
'Style', 'Text', ...
'Units', 'Normalized', ...
'String', Opt.Label, ...
'Position', [Opt.TextX, Opt.YPos + Opt.FigHeight - Opt.YSpace - ...
Opt.TxtHeight, Opt.TextWidth, Opt.TxtHeight]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LocalAssignMat
% Save display to Matrix
function LocalAssignMat()
Data = get(findobj('Tag', 'ViewEDFFigure'), 'UserData');
if length(Data.EDF)==0
errordlg('No EDF-File is open!', 'Error');
return;
end
answer = inputdlg({'Target name'}, 'Save to cell-array', 1, {''});
if (length(answer) == 0)
return;
end
cnt = 0;
for j=1:length(Data.EDF)
for i=1:length(Data.Display.EDF(j).ShowSignals)
cnt = cnt+1;
showsig = Data.Display.EDF(j).ShowSignals(i);
res{cnt} = Data.EDF(j).Record{showsig};
end
end
for j=1:length(Data.Plugin)
for i=1:length(Data.Display.Plugin(j).ShowSignals)
cnt = cnt+1;
Data.Plugin(j)
showsig = Data.Display.Plugin(j).ShowSignals(i);
res{cnt} = Data.Plugin(j).EDF.Record{showsig};
end
end
assignin('base', answer{1}, res);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LocalGetEDFInfo
% get information of all open EDF files
function [res] = LocalGetEDFInfo(Which, EDF)
temp = cat(1,EDF(:).Head);
switch Which
case 'NRec'
res = cat(1,temp(:).NRec);
case 'Dur'
res = cat(1,temp(:).Dur);
case 'SPR'
res = cat(1,temp(:).SPR);
case 'FileDur'
res = cat(1,temp(:).NRec) .* cat(1,temp(:).Dur);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LocalAddPlugin
% Add plugin function
function LocalAddPlugin()
Data = get(findobj('Tag', 'ViewEDFFigure'), 'UserData');
if length(Data.EDF)==0
errordlg('No EDF-File is open!', 'Error');
return;
end
res=inputdlg({ 'Enter Plugin name','Label (Optional)', ...
'Parameters (Optional)'}, 'Select Plugin', 1, { '', '', ''});
if isempty(res)
return;
end
plugname = res{1};
pluglabel = res{2};
plugopt = res{3};
if isempty(pluglabel)
pluglabel = plugname;
end
if ~exist(plugname, 'file');
errordlg(sprintf('Plugin %s can not be found in standard search path', ...
upper(plugname)), 'Plugin Error');
return
end;
% select EDF file if several files are open
infile = 1;
if (length(Data.EDF) > 1)
[infile, cancelled] = LocalSelectEDFFile({'EDF-data passed to plugin', ...
'Select'}, Data.EDF);
if cancelled
return
end
end
% set all variables
ind = length(Data.Plugin) + 1;
Data.Plugin(ind).Name = plugname;
Data.Plugin(ind).Label = pluglabel;
Data.Plugin(ind).UserData = plugopt;
Data.Plugin(ind).EDFFile = infile;
LocalWatchOn;
[Data.Plugin(ind).EDF, Data.Plugin(ind).UserData] = ...
feval(Data.Plugin(ind).Name, Data.EDF(infile), ...
Data.Plugin(ind).UserData, 'Reset');
LocalWatchOff;
Data.Display.Plugin(ind).ShowSignals = 1:Data.Plugin(ind).EDF.Head.NS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -