📄 plotfig.m
字号:
nmax=round((tval/per)+epochint);
nmin=round((tmin/per)+epochint);
else
nmax=round((tval/per)+1);
nmin=round((tmin/per)+1);
end
set(handles.slidertime,'Value',tval);
end
end
% Set nmax, nmin, tmin, and tmax for time scrolling
if tval>=tlim && isequal(max_scroll,0)
if isequal(plot_type,3)
nmax=round((tval/per)+epochint);
tmax=(nmax-epochint)*per;
tmin=tmax-tlim;
nmin=round((tmin/per)+epochint);
elseif dispval==prev_dispval
nmax=round((tval/per)+1);
nmin=round((nmax-nlim)+1);
tmin=(nmax-nlim)*per;
tmax=tmin+tlim;
end
% 4. When scrolling to the min less than 0.
elseif tval<tlim && isequal(max_scroll,0)
tmin=0;
if tmax>tlim
tmax=tlim;
else
max_scroll=1;
end
tval=tmax;
set(handles.slidertime,'Value',tval); % set tval to tmax.
if isequal(plot_type,3)
nmax=round((tmax/per)+epochint);
nmin=round((tmin/per)+epochint);
else
nmax=round((tmax/per)+1);
nmin=1;
end
end
setappdata(hMainGui,'prev_tval',tval);
setappdata(hMainGui,'prev_tmin',tmin);
% --------- 5. Plotting Data ----------------------
% ------- Data to plot --------
tbc_data=getappdata(hMainGui,'tbc_data');
tbc_corrdata=getappdata(hMainGui,'tbc_corrdata');
t=tmin:per:tmax;
plot(t,tbc_data(nmin:nmax,val),'r'), hold on
plot(t,tbc_corrdata(nmin:nmax,val))
ylabel('Amplitude','FontSize',8),xlabel('Time(s)','FontSize',8)
if (get(handles.on_grid_radiobutton,'value')==1)
grid on;
else
grid off;
end
hleg=legend('Original Data','Corrected Data',1); % hleg = handles for legend
set(hleg,'Color','none','Orientation','horizontal','FontSize',8,'Box', 'off');
% --------- 6. Axis Settings ----------------------
if isequal(starting_plot,1)
axis tight
y_lim=ylim; % to get the current ylim
ymin=y_lim(1);
ymax=y_lim(2);
axis([tmin tmin+tlim ymin ymax]);
setappdata(hMainGui,'y_lim',y_lim);
else
y_lim=getappdata(hMainGui,'y_lim');
ymin=y_lim(1);
ymax=y_lim(2);
if ~isequal(max_scroll,1)
axis([tmin tmax+1e-6 ymin ymax]); % 1e-6 is to improve the visibility
else
axis([tmin tmin+tlim ymin ymax]);
end
end
setappdata(hMainGui,'starting_plot',0);
catch
str={' No plot to display.'
''
'Please check data and try again.'};
warn_plot1=msgbox(str,'Warning','warn','modal');
waitfor(warn_plot1);
return
end
% --- Executes during object creation, after setting all properties.
function popupchannel_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% ------------------------------------------------------------------
% --- Executes on selection change in popupdisplay.
function popupdisplay_Callback(hObject, eventdata, handles)
popupchannel_Callback(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function popupdisplay_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% ----------------------------------------
% Slider bar
% ----------------------------------------
% --- Executes on slidertime movement.
function slidertime_Callback(hObject, eventdata, handles)
% Hints: get(hObject,'Value') returns position of slidertime
% get(hObject,'Min') and get(hObject,'Max') to determine range of slidertime
popupchannel_Callback(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties. Used to initialise the slider ---
function slidertime_CreateFcn(hObject, eventdata, handles)
% Hint: slidertime controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Tooltipstring','Move slider to adjust the time scale');
% --- Executes on slider movement.
function sliderepoch_Callback(hObject, eventdata, handles)
epochval=get(hObject,'Value');
set(handles.slidertxt1,'string',epochval);
popupchannel_Callback(hObject, eventdata, handles);
% --- Executes during object creation, after setting all properties.
function sliderepoch_CreateFcn(hObject, eventdata, handles)
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Tooltipstring','Move slider to select the epoch channel');
% ----------------------------------------
% Radio buttons
% ----------------------------------------
% --- Executes on button press in on_grid_radiobutton.
function on_grid_radiobutton_Callback(hObject, eventdata, handles)
% Hint: get(hObject,'Value') returns toggle state of on_grid_radiobutton
if get(handles.on_grid_radiobutton,'value')==1
grid on
else
grid off
end
% ----------------------------------------
% Other Functions
% ----------------------------------------
function save_fig_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function save_img_jpg_Callback(hObject, eventdata, handles)
[cdata,colorMap]=getframe(gcf); % getframe used to save snapshot
imwrite(cdata,'figure.jpg'); % saving it as image
% --------------------------------------------------------------------
function save_img_ai_Callback(hObject, eventdata, handles)
print(gcf,'-dill', 'figure');
% --------------------------------------------------------------------
function save_img_pdf_Callback(hObject, eventdata, handles)
print(gcf,'-dpdf', 'figure');
% --------------------------------------------------------------------
function save_img_png_Callback(hObject, eventdata, handles)
print(gcf,'-dpng', 'figure');
% --------------------------------------------------------------------
function save_img_bmp_Callback(hObject, eventdata, handles)
print(gcf,'-dbmp', 'figure');
% --------------------------------------------------------------------
function save_img_as(hObject, eventdata, handles)
[fname, pathname, filterindex] = uiputfile( ...
{'*.ai', 'Adobe Illustrator file (*.ai)'; ...
'*.bmp','Bitmap file (*.bmp)'; ...
'*.bmp','Monochrome Bitmap file (*.bmp)'; ...
'*.eps','EPS file (*.eps)'; ...
'*.emf','Enhanced metafile (*.emf)'; ...
'*.jpg','JPEG image (*.jpg)'; ...
'*.pcx','Paintbrush 24-bit file (*.pcx)'; ...
'*.pbm','Portable Bitmap file (*.pbm)'; ...
'*.pdf','Portable Document Format (*.pdf)'; ...
'*.pgm','Portable Graymap file (*.pgm)'; ...
'*.png','Portable Networks Graphics file (*.png)'; ...
'*.ppm','Portable Pixmap file (*.ppm)'; ...
'*.tif','TIFF image (*.tif)'}, ...
'Save as');
idx=strfind(fname,'.');
extname=fname(idx+1:end);
fname=fname(1:idx-1);
% Converting the extension name to all capital letters
for ext_idx=1:length(extname)
if extname(ext_idx)>=97 && extname(ext_idx)<=122
extname(ext_idx)=extname(ext_idx)-32;
end
end
% Assign the extension name to the corresponding filterindex
switch(extname)
case 'AI'
filterindex=1;
case {'BMP','DIB'} % case 2 and 3 have the same extensions
filterindex=2;
case 'EPS'
filterindex=4;
case 'EMF'
filterindex=5;
case {'JPG','JPEG','JPE','JFIF'}
filterindex=6;
case 'PCX'
filterindex=7;
case 'PBM'
filterindex=8;
case 'PDF'
filterindex=9;
case 'PGM'
filterindex=10;
case 'PNG'
filterindex=11;
case 'PPM'
filterindex=12;
case {'TIF','TIFF'}
filterindex=13;
end
switch(filterindex)
case 1
print(gcf,'-dill',[pathname fname]);
case 2
print(gcf,'-dbmp',[pathname fname]);
case 3
print(gcf,'-dbmpmono',[pathname fname]);
case 4
print(gcf,'-depsc',[pathname fname]);
case 5
print(gcf,'-dmeta',[pathname fname]);
case 6
print(gcf,'-djpeg',[pathname fname]);
case 7
print(gcf,'-dpcx',[pathname fname]);
case 8
print(gcf,'-dpbm',[pathname fname]);
case 9
print(gcf,'-dpdf',[pathname fname]);
case 10
print(gcf,'-dpgm',[pathname fname]);
case 11
print(gcf,'-dpng',[pathname fname]);
case 12
print(gcf,'-dppm',[pathname fname]);
case 13
print(gcf,'-dtiff',[pathname fname]);
end
function clear_axes()
h=findall(gcf,'Tag','axes1');
legend('off');
cla(h);
function clear_vars()
hMainGui = getappdata(0,'hMainGui');
% -------- Delete --------------------
% var={'pnt','plot_type','type_tbc',...
% 'swp','prev_epochval','prev_val',...
% 'tmax','chstr','tmax','dispval','prev_dispval',...
% 'display_length','prev_tval_max',...
% }; % set the name of the variables that were set up
% ------------------------------------
% -------- Additional ----------------
var={'starting_plot','plot_type','range','tmax','display_length',...
'prev_val','prev_dispval','prev_epochval','prev_tlim','prev_tval_max',...
'prev_tval','prev_tmin','y_lim',...
};
% ------------------------------------
for i=1:length(var)
if ~isempty(getappdata(hMainGui,var{i}))
rmappdata(hMainGui,var{i}); % to remove the set variables
end
end
function zoom_default(hObject, eventdata, handles)
hMainGui = getappdata(0,'hMainGui');
prev_tlim=getappdata(hMainGui,'prev_tlim'); % get the previous tlim
prev_tmin=getappdata(hMainGui,'prev_tmin');
% ------ Delete -------------
% tmin=getappdata(hMainGui,'tmin');
% ---------------------------
axis tight
y_lim=ylim;
ymin=y_lim(1);
ymax=y_lim(2);
axis([prev_tmin prev_tmin+prev_tlim ymin ymax]);
setappdata(hMainGui,'y_lim',y_lim);
function zoomin(hObject, eventdata, handles)
hMainGui=getappdata(0, 'hMainGui');
current_axes=getappdata(hMainGui,'current_axes');
zoomin_factor=10; % magnification factor in percentage
prev_ylim=ylim;
prev_ymax=prev_ylim(2);
prev_ymin=prev_ylim(1);
yss=(prev_ymax+prev_ymin)/2;
prev_delta=prev_ymax-yss;
delta=(1-zoomin_factor/100)*prev_delta;
ymax=yss+delta;
ymin=yss-delta;
y_lim=[ymin ymax];
set(current_axes,'Ylim',y_lim);
setappdata(hMainGui,'y_lim',y_lim);
function zoomout(hObject, eventdata, handles)
hMainGui=getappdata(0, 'hMainGui');
current_axes=getappdata(hMainGui,'current_axes');
zoomout_factor=10; % magnification factor in percentage
prev_ylim=ylim;
prev_ymax=prev_ylim(2);
prev_ymin=prev_ylim(1);
yss=(prev_ymax+prev_ymin)/2;
prev_delta=prev_ymax-yss;
delta=(1+zoomout_factor/100)*prev_delta;
ymax=yss+delta;
ymin=yss-delta;
y_lim=[ymin ymax];
set(current_axes,'Ylim',y_lim);
setappdata(hMainGui,'y_lim',y_lim);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -