📄 plotfig.m
字号:
function varargout = plotfig(varargin)
% Last Modified by GUIDE v2.5 07-Jul-2007 16:38:16
% PLOTFIG: Display the results of the corrected data
% PLOTFIG, by itself, creates a new PLOTFIG or raises the existing
% singleton*.
%
% H = PLOTFIG returns the handle to a new PLOTFIG or the handle to
% the existing singleton*.
%
% PLOTFIG('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PLOTFIG.M with the given input arguments.
%
% PLOTFIG('Property','Value',...) creates a new PLOTFIG or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before plotfig_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property
% application
% stop. All inputs are passed to plotfig_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
%
% Programmed and Copyright by Tony Tanoyo: tony.tanoyo@gmail.com
% $Revision: 01 $ $Date: 24/10/2007$
%
% Files Contribution:
% Yair Altman for the statusbar function, May 2007.
% Daniel Claxton for the workbar function, March 2005.
% Xiaoning (David) Yang for the keep function, 1998.
% Revision control:
% 251007: Widen the title on the plotfig figure (GUI) file to accomodate long title like sample_to_be_corrected_data
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @plotfig_OpeningFcn, ...
'gui_OutputFcn', @plotfig_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before plotfig is made visible. For default configuration.
function plotfig_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose *** default *** command line output for plotfig
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% ----------------- Clear Variables and Axes --------------
% Set hMainGui to the root and clear variables
hMainGui = getappdata(0, 'hMainGui');
clear_vars;
% Clearing and setting the current axes on the second GUI
axes(handles.axes1);
legend('off');
cla(handles.axes1);
setappdata(hMainGui,'current_axes',handles.axes1);
setappdata(hMainGui,'starting_plot',1); % set the starting_plot indicator before the execution
% ------------------- Handles Settings ----------------------
% Set the paper position to auto and inverthardcopy
set(hObject,'PaperPositionMode','auto');
set(hObject,'InvertHardcopy','off');
% Set the off radio button 'on'
set(handles.on_grid_radiobutton,'Value',0); % set the grid off at the start
% Set the title of GUI
tbc_fname=getappdata(hMainGui,'fname3');
set(handles.title,'String',['EOG plot of "' tbc_fname '" data']);
% Modifying the figure toolbar
toggletool=findall(hObject,'Type','uitoggletool');
pushtool=findall(hObject,'Type','uipushtool');
if length(pushtool)==6 && length(toggletool)==8
set(pushtool(4),'ClickedCallback',@save_img_as);
set(toggletool(5),'Separator','on');
zoomout_pic=get(toggletool(6),'CData');
zoomin_pic=get(toggletool(7),'CData');
zoomdefault_pic=get(pushtool(1),'CData');
parents=get(toggletool(6),'Parent');
% Create zoom out, zoom in, zoom default, data cursor, and pan pushtools
zoomin_pushtool=uipushtool(parents,'Cdata',zoomin_pic,'ClickedCallback',@zoomin,'TooltipString','Zoom In','Separator','on');
zoomout_pushtool=uipushtool(parents,'Cdata',zoomout_pic,'ClickedCallback',@zoomout,'TooltipString','Zoom Out');
zoomdefault_pushtool=uipushtool(parents,'Cdata',zoomdefault_pic,'ClickedCallback',@zoom_default,'TooltipString','Revert to Default');
for i=[1,2,4,6,7,8]
delete(toggletool(i));
end
for i=[1,2,3,5,6]
delete(pushtool(i));
end
end
% ---------- Assign the plot_type, per, pnt, swp -------------
keep('hMainGui','handles','hObject','eventdata');
% Get the hdr_tbc, types, and period
hdr_tbc=getappdata(hMainGui,'hdr_tbc');
% ------- Additional ---------
type_tbc=getappdata(hMainGui,'type_tbc');
per=getappdata(hMainGui,'per');
% ----------------------------
% ----------- Delete -----------
% type_tbc=hdr_tbc{6,1};
% idx=strfind(type_tbc,']');
% type_tbc=strtrim(type_tbc((idx+1):end));
% str=hdr_tbc{5,1}; % get line 5 of the header
% idx=strfind(str,']');
% freq=str2num(strtrim(str((idx+1):end))); % freq of the signal
% per=1/freq;
% setappdata(hMainGui,'per',per);
% -------------------------------
if strcmp(type_tbc,'Continuous')
plot_type=1;
elseif strcmp(type_tbc,'Average')
plot_type=2;
% --------- Additional ------------
pnt=getappdata(hMainGui,'pnt');
% ---------------------------------
% ----------- Delete -----------
% strpnt=hdr_tbc{7,1};
% idx=strfind(strpnt,']');
% pnt=str2num(strtrim(strpnt((idx+1):end)));
% setappdata(hMainGui,'pnt',pnt);
% -------------------------------
elseif strcmp(type_tbc,'Epoch')
plot_type=3;
% --------- Additional ------------
pnt=getappdata(hMainGui,'pnt');
swp=getappdata(hMainGui,'swp');
% ---------------------------------
% ----------- Delete -----------
% strpnt=hdr_tbc{8,1};
% idx=strfind(strpnt,']');
% pnt=str2num(strtrim(strpnt((idx+1):end)));
% setappdata(hMainGui,'pnt',pnt);
% swp=hdr_tbc{10,1};
% idx=strfind(swp,']');
% swp=str2num(strtrim(swp((idx+1):end)));
% setappdata(hMainGui,'swp',swp);
% -------------------------------
end
set(handles.popupdisplay,'Visible','on'); % turning on the popupdisplay and txt
set(handles.display_length_text,'Visible','on');
setappdata(hMainGui,'plot_type',plot_type);
% ---------- Sliderstep Settings for Horizontal Time and Epoch -----------
tbc_size=getappdata(hMainGui,'tbc_size');
if isequal(plot_type,1) || isequal(plot_type,2)
set(handles.slidertxt1,'visible','off');
set(handles.slidertxt2,'visible','off');
set(handles.slidertxt3,'visible','off');
set(handles.epoch_uipanel,'Visible','off');
set(handles.sliderepoch,'Visible','off');
elseif isequal(plot_type,3)
set(handles.slidertxt1,'Visible','on','Tooltipstring','Epoch channel','string',1);
set(handles.slidertxt2,'Visible','on');
set(handles.slidertxt3,'Visible','on','Tooltipstring','Total no of epoch channels','string',swp);
set(handles.epoch_uipanel,'Visible','on');
set(handles.sliderepoch,'Visible','on');
epoch_arrow_step=1/(swp-1);
epoch_trough_step=epoch_arrow_step;
set(handles.sliderepoch,'SliderStep',[epoch_arrow_step epoch_trough_step],'Min',1,'Max',swp);
end
if isequal(plot_type,1)
tmax=(tbc_size-1)*per;
elseif isequal(plot_type,2) || isequal(plot_type,3)
tmax=(pnt-1)*per;
end
tmin=0;
range=tmax-tmin;
set(handles.slidertime,'Min',tmin,'Max',tmax);
setappdata(hMainGui,'range',range);
setappdata(hMainGui,'tmax',tmax);
% ---------- Popup Channel Select Settings -------------
% Assign the popupchannel to the ch_labels
ch_label=getappdata(hMainGui,'ch_label');
set(handles.popupchannel,'string',ch_label);
popval=get(handles.popupchannel,'value');
if popval~=1
set(handles.popupchannel,'value',1); % Assign the popupchannel to the first channel for default
end
% ---------- Popup Display Length Settings -------------------
% Assign the popupdisplay to the display length string
display_length={'0.2','0.4','0.6','0.8','1','2','3','4','5'};
setappdata(hMainGui,'display_length',display_length);
set(handles.popupdisplay,'string',display_length);
% --------- Calculating the best fit display length ----------
dispval=1;
display_num=str2double(display_length);
for k=1:length(display_num)
quotient=tmax/display_num(k);
if quotient>=1
dispval=k;
else
break
end
end
set(handles.popupdisplay,'value',dispval);
setappdata(hMainGui,'prev_dispval',dispval);
popupchannel_Callback(hObject, eventdata, handles); % plot the tbc_data
% --- Outputs from this function are returned to the command line.
function varargout = plotfig_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
% ----------------------------------------
% Popup channel
% ----------------------------------------
% --- Executes on selection change in popupchannel.
function popupchannel_Callback(hObject, eventdata, handles)
% Hints: contents = get(hObject,'String') returns popupchannel contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupchannel
try
hMainGui = getappdata(0, 'hMainGui');
clear_axes;
% Get the previous time parameters
prev_tmin=getappdata(hMainGui,'prev_tmin');
prev_tlim=getappdata(hMainGui,'prev_tlim');
prev_tval=getappdata(hMainGui,'prev_tval'); % the value previously found from the slidertime bar
prev_tval_max=getappdata(hMainGui,'prev_tval_max'); % the value of tval before reaching tmax
prev_dispval=getappdata(hMainGui,'prev_dispval');
tmax=getappdata(hMainGui,'tmax'); % max time for the whole data initially
% Get the plot parameters
plot_type=getappdata(hMainGui,'plot_type');
per=getappdata(hMainGui,'per');
pnt=getappdata(hMainGui,'pnt');
range=getappdata(hMainGui,'range');
starting_plot=getappdata(hMainGui,'starting_plot'); % get the starting_plot identifier
% ------- 1. Channel Select Settings --------------
% Get the previous and current channel select values
prev_val=getappdata(hMainGui,'prev_val');
val=get(handles.popupchannel,'Value'); % channel selection value from the popup menu
setappdata(hMainGui,'prev_val',val); % set to previous value of popup selection
% ------- 2. Epoch Select Settings ----------------
% Get the current channel and epoch selects value
prev_epochval=getappdata(hMainGui,'prev_epochval');
epochval=get(handles.sliderepoch,'Value');
setappdata(hMainGui,'prev_epochval',epochval); % set to previous value of sliderepoch channel selection
% Calculates epochint: epoch starting integer value (the min pnt of each epoch type)
if isequal(plot_type,3)
epochint=pnt*(epochval-1)+epochval;
end
% ------- 3. Display Length Settings --------------
% Get the current display length selected and calculates tlim and nlim
display_length=getappdata(hMainGui,'display_length');
dispval=get(handles.popupdisplay,'value');
if ~isequal(prev_epochval,epochval)
display_num=str2double(display_length);
for k=1:length(display_num)
quotient=tmax/display_num(k);
if quotient>=1
dispval=k;
else
break
end
end
end
set(handles.popupdisplay,'value',dispval);
for k=1:length(dispval)
tlim=str2double(display_length{dispval}); % tlim calculated based on the dispval chosen.
nlim=tlim/per+1;
end
setappdata(hMainGui,'prev_dispval',dispval);
setappdata(hMainGui,'prev_tlim',tlim);
if ~isequal(prev_dispval,dispval) || isequal(starting_plot,1)
slider_step=tlim/range;
if slider_step>1
slider_step=1;
end
set(handles.slidertime,'SliderStep',[slider_step slider_step]);
end
max_scroll=0; % max_scroll=0 shows that it has not reach max scroll yet
% -------- 4. Calculating nmin, nmax, tmin, and tmax --------
% Test whether the number of datapoints > limit display length of time
if isempty(prev_val)
if isequal(plot_type,3)
epochval=1; % initially start epoch channel selection=1 and tval=1
set(handles.slidertxt1,'string',epochval);
set(handles.sliderepoch,'Value',1);
end
set(handles.slidertime,'Value',tlim);
tval=tlim;
starting_plot=1;
else
% 1. When scrolling the time scale only or when epoch is changed.
if dispval==prev_dispval || epochval~=prev_epochval
tval=get(handles.slidertime,'Value');
% 2. When scrolling the time and reaching the max time.
if (abs(prev_tval-tmax)<1e-12 && tmax>tlim) || (abs(tval-tmax)<1e-12 && tmax>tlim)
if prev_tval<=tval
% scrolling down from small to maximum time
max_scroll=1;
tmax=tval;
if prev_tval==tval
tmin=prev_tmin;
else
tmin=prev_tval;
setappdata(hMainGui,'prev_tval_max',prev_tval);
end
if isequal(plot_type,3)
nmax=round((tval/per)+epochint);
nmin=round((tmin/per)+epochint);
else
nmax=round((tval/per)+1);
nmin=round((tmin/per)+1);
end
else
% scrolling up from max to smaller time
tval=prev_tval_max;
set(handles.slidertime,'Value',tval);
end
end
% 3. When display_length is changed.
elseif dispval~=prev_dispval
tmin=prev_tmin;
if tmin+tlim<tmax
tmax=tmin+tlim;
else
max_scroll=1;
end
tval=tmax;
if isequal(plot_type,3)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -