📄 graf_tool.m
字号:
%graf_tool is a set of functions which can be used to process figure properties.
%This function can either be used as an individual function:
%
% graf_tool
%
%or used as part of CrtlLAB:
%
% graf_tool(nTask,arg1)
%where
% nTask -- system analysis code, as shown in sys_analysis
% arg1 -- extra arguments
%
%The functions available in the module are
%
% figwin_menu -- create menu system on the figure window
% graf_toolbar --- add toolbar for MATLAB is higher than 5.2.
% chg_graphs -- change graph properties
% graf_file -- administrates the File menu
% redraw_plot -- re-draw the previously saved plots
% graf_capture -- extracts the plot elements on the existing plots
% shifty_plt -- shift the y axis of the plot down or up
% add_extramenu -- add an extra menu item for system analysis, if required
%
%Copyright (c) 1997-1999 by Professor Dingyu Xue
%School of Information Science and Engineering, Northeastern University
%Shenyang 110006, P R China
%Email: xue_dy@hotmail.com
%---------------------------------------------------------------------------------
function graf_tool(nTask,arg1)
[v,d]=version; v1=eval(v(1)); v2=eval(v(3));
switch nargin
case {0,1}, %initial program interface
if nargin==0, %when it is used as an independent program
nTask=3; strWndTitle='GrafTools -- Plot Window'; posPlot=[0.2425 0.232 0.5 0.45];
else %when it is used under CtrlLAB
WindwName=str2mat('Bode Diagram','Nyquist Plots','Nichols Charts',...
'Inverse Nyquist Plots','Root Locus','Step Responses',...
'Impulse Responses','Stability Margins');
strWndTitle=WindwName(nTask,:); PltWndRect=[0.48625 0.465 0.5 0.467];
rectMod=[0.0188,0.025,0,0]; posPlot=PltWndRect-(nTask-1)*rectMod;
end
h_win=findobj('Name',strWndTitle);
if length(h_win)==0, %if there is no such a window, then open a new one
h_win=figure('Units','normalized','Position',posPlot,...
'NumberTitle','off','Name',strWndTitle,'MenuBar','none','Color',0.8*[1,1,1],...
'Tag','CtrlLABFigs','Interruptible','on',...
'PaperUnits','inch','PaperPosition',[0.15,8,5,3.5]);
%the reason why such a PaperPosition argument is set is that the text
%size/figure size should be preserved when printed in EPS files. It
%does not have any effect on other copy format.
if nargin==0, figwin_menu(nTask,[]);
else, figwin_menu(nTask); end
if v1>=5 & v2>=2,
set(gcf,'ResizeFcn','graf_tool(3,[]);');
graf_toolbar([]); set_contxtmenu(5);
end
else, figure(h_win); end
case 2
switch nTask
case 0, graf_file(arg1); %processing the File menu
case 1, chg_graphs(arg1); %taggle graphics properties
case 2, chg_graphs(arg1,[]); %update graphics properties
case 3, graf_toolbar(arg1);
case 4, %shift down/up the axes
v=get(gco,'Value'); if v==0, v=-1; end, shifty_plt(v);
end
end
%---------------------------------------------------------------
%figwin_menu is used to create menu system on the figure window.
%---------------------------------------------------------------
function figwin_menu(nTask,arg1)
if nargin==0, nTask=1; end
%buiding the menu system for Graf_Tool
%Build the File menu
hMOptions(2)=uimenu(gcf,'Label','&File');
hMOptions(7)=uimenu(hMOptions(2),'Label','&New','CallBack','graf_tool(1,5);');
hMOptions(50)=uimenu(hMOptions(2),'Label','&Open','CallBack','graf_tool(0,1);');
hMOptions(51)=uimenu(hMOptions(2),'Label','&Save','CallBack','graf_tool(0,2);');
hMOptions(52)=uimenu(hMOptions(2),'Label','Save &As','CallBack','graf_tool(0,3);');
hMOptions(53)=uimenu(hMOptions(2),'Separator','on','Label','Axis and &Grids');
hMOptions(3)=uimenu(hMOptions(53),'Label','with &Grids','Checked','off','CallBack','graf_tool(1,1);');
hMOptions(4)=uimenu(hMOptions(53),'Label','with &Box','Checked','on','CallBack','graf_tool(1,2);');
hMOptions(5)=uimenu(hMOptions(53),'Label','&Hold Figure','Checked','off','CallBack','graf_tool(1,3);');
hMOptions(60)=uimenu(hMOptions(2),'Label','Clear','CallBack','delete(extra_funs(2));');
hMOptions(6)=uimenu(hMOptions(53),'Label','with Square Axis',...
'Checked','off','Visible','off','CallBack','graf_tool(1,4);');
hMOptions(40)=uimenu(hMOptions(2),'Label','Preferences...','Separator','on','CallBack','plot_proc(1);');
hMOptions(36)=uimenu(hMOptions(2),'Label','Print');
hMOptions(61)=uimenu(hMOptions(36),'Label','Print on Printer','CallBack','plot_proc(19,[]);');
hMOptions(37)=uimenu(hMOptions(36),'Label','Copy as &MetaFile',...
'Separator','on','CallBack','plot_proc(17,[]);');
hMOptions(38)=uimenu(hMOptions(36),'Label','Copy as &Bitmap','CallBack','plot_proc(18,[]);');
hMOptions(39)=uimenu(hMOptions(36),'Label','Save in Mono &EPS File','CallBack','plot_proc(15,0);');
hMOptions(63)=uimenu(hMOptions(36),'Label','Save in Color &EPS File','CallBack','plot_proc(16,0);');
hMOptions(62)=uimenu(hMOptions(36),'Label','Printer Setup...','Separator','on','CallBack','print -v;');
hMOptions(64)=uimenu(hMOptions(36),'Label','Page Setup...','CallBack','pagedlg;');
hMOptions(41)=uimenu(hMOptions(2),'Label','Close Window','Separator','on','CallBack','close(gcf);');
%Enable square axis format for some cases
if any([2,4,5]==nTask|nargin==2), set(hMOptions(6),'Visible','on'); end
%Build Legends Processing menu
hMOptions(8)=uimenu(gcf,'Label','&Legends');
hMOptions(9)=uimenu(hMOptions(8),'Label','&New Legend','Callback','legd_proc(1);');
hMOptions(10)=uimenu(hMOptions(8),'Label','&Edit Legend','Callback','legd_proc(2);');
hMOptions(11)=uimenu(hMOptions(8),'Label','&Move Legend','Callback','legd_proc(3);');
hMOptions(13)=uimenu(hMOptions(8),'Label','&Add a Line','Callback','legd_proc(5);');
hMOptions(14)=uimenu(hMOptions(8),'Label','Add an Arro&w','Callback','legd_proc(8);');
hMOptions(12)=uimenu(hMOptions(8),'Separator','on','Label','&Delete a Legend','Callback','legd_proc(4);');
hMOptions(42)=uimenu(hMOptions(8),'Label','&Remove All Legends','Callback','legd_proc(9);');
hMOptions(58)=uimenu(hMOptions(8),'Label','&Change a Legend Color','Callback','legd_proc(23);');
hMOptions(7)=uimenu(hMOptions(8),'Label','&Cursor Positioning','Separator','on','CallBack','legd_proc(18);');
hMOptions(15)=uimenu(hMOptions(8),'Label','&Properties ...','Callback','legd_proc(13);');
%Building the Zooming Faciliies menu
hMOptions(16)=uimenu(gcf,'Label','&Zooming');
hMOptions(17)=uimenu(hMOptions(16),'Label','&Zooming','Checked','off','CallBack','plot_proc(1,0,0);');
hMOptions(18)=uimenu(hMOptions(16),'Label','&X-axis Zooming','CallBack','plot_proc(2,0,0);');
hMOptions(19)=uimenu(hMOptions(16),'Label','&Y-axis Zooming','CallBack','plot_proc(3,0,0);');
hMOptions(20)=uimenu(hMOptions(16),'Label','&Full','CallBack','plot_proc(4,0,0);');
hMOptions(21)=uimenu(hMOptions(16),'Label','&User Define...','Separator','on','CallBack','plot_proc(5,0,0);');
%Building the Curves Processing menu
hMOptions(22)=uimenu(gcf,'Label','Curves');
hMOptions(23)=uimenu(hMOptions(22),'Label','&Delete a Certain Curve','CallBack','plot_proc(1,0);');
hMOptions(24)=uimenu(hMOptions(22),'Label','&Change Curve Color','CallBack','plot_proc(2,0);');
hMOptions(25)=uimenu(hMOptions(22),'Label','&Change Curve Line Style');
hMOptions(26)=uimenu(hMOptions(25),'Label','&Solid Line','Checked','on','CallBack','plot_proc(3,0);');
hMOptions(27)=uimenu(hMOptions(25),'Label','&Dash Line','Checked','off','CallBack','plot_proc(4,0);');
hMOptions(28)=uimenu(hMOptions(25),'Label','D&otted Line','Checked','off','CallBack','plot_proc(5,0);');
hMOptions(29)=uimenu(hMOptions(25),'Label','D&ash Dotted Line','Checked','off','CallBack','plot_proc(6,0);');
hMOptions(30)=uimenu(hMOptions(22),'Label','&Change Curve Marker');
hMOptions(31)=uimenu(hMOptions(30),'Label','* Signs','Checked','on','CallBack','plot_proc(7,0);');
hMOptions(32)=uimenu(hMOptions(30),'Label','+ Signs','Checked','off','CallBack','plot_proc(8,0);');
hMOptions(33)=uimenu(hMOptions(30),'Label','o Signs','Checked','off','CallBack','plot_proc(9,0);');
hMOptions(34)=uimenu(hMOptions(30),'Label','x Signs','Checked','off','CallBack','plot_proc(10,0);');
hMOptions(35)=uimenu(hMOptions(30),'Label','. Signs','Checked','off','CallBack','plot_proc(11,0);');
hMOptions(46)=uimenu(hMOptions(30),'Label','Remove Markers','Separator','on','CallBack','plot_proc(12,0);');
hMOptions(43)=uimenu(hMOptions(22),'Label','Line Thickness');
hMOptions(44)=uimenu(hMOptions(43),'Label','Thicker','CallBack','plot_proc(13,0);');
hMOptions(45)=uimenu(hMOptions(43),'Label','Thinner','CallBack','plot_proc(14,0);');
hMOptions(59)=uimenu(hMOptions(22),'Label','Change Plot Range ...',...
'Separator','on','Visible',extra_funs(6,nargin<2),'CallBack','legd_proc(24);');
hMOptions(47)=uimenu(hMOptions(22),'Label','Line Properties','CallBack','legd_proc(22);');
hMOptions=add_extramenu(nTask,hMOptions);
%Building the Help Facilities menu
hMOptions(1)=uimenu(gcf,'Label','&Help');
hMOptions(49)=uimenu(hMOptions(1),'Label','Help on Graphics Toolbox','CallBack','clab_help(29);');
hMOptions(55)=uimenu(hMOptions(1),'Label','Help on Legends','CallBack','clab_help(21);');
hMOptions(56)=uimenu(hMOptions(1),'Label','Help on Zooming','CallBack','clab_help(20);');
hMOptions(57)=uimenu(hMOptions(1),'Label','Help on Curve Editing','CallBack','clab_help(30);');
hMOptions(48)=uimenu(hMOptions(1),'Label','About Graphics ToolKit ...',...
'Separator','on','CallBack','clab_help(27);');
%set the uicontrols for legend editting facilities. The initial status of the
%controls are set to invisible as a start.
hLegd(1)=uicontrol('Style','Edit','String','','Visible','off',...
'Units','normalized','Position',[0.20,0.9,0.6,0.07],...
'HorizontalAlignment','left','BackgroundColor',[1,1,1],'Callback','legd_proc(10);');
if any(6:7==nTask),
ww=[5,0.001,0.1,1e-3,0.1,5,1,5,1,5];
set(gcf,'UserData',{hMOptions,[hLegd,0],[],nTask,'',ww});
else
set(gcf,'UserData',{hMOptions,[hLegd,0],[],nTask});
end
%-------------------------------------------------------------------------------------
%graf_toolbar is used to add toolbar to the main graphics window if the version of
%MATLAB is higher than 5.2.
%-------------------------------------------------------------------------------------
function graf_toolbar(key)
[v,d]=version; v1=eval(v(1)); v2=eval(v(3));
if v1>=5 & v2>=2,
yy=get(gcf,'Position'); screen=get(0,'ScreenSize');
ymax=yy(4)*screen(4)-20; xmax=yy(3)*screen(3);
load ctrllab_cdata; load graf_cdata
yy=[findobj(gcf,'Tag','Tools');findobj(gcf,'Tag','Toolz')]; delete(yy);
if length(key)==0
uicontrol('Style','Frame','Units','pixels','Position',[1,ymax,xmax,20],...
'BackgroundColor',0.8*[1,1,1],'ForegroundColor',0.8*[1,1,1],'Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[5,ymax,20,20],...
'CData',fnew_dat,'CallBack','graf_tool(1,5);','TooltipString','Clear figure','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[25,ymax,20,20],...
'CData',fopen_dat,'CallBack','graf_tool(0,1);','TooltipString','Load graphs','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[45,ymax,20,20],...
'CData',fsave_dat,'CallBack','graf_tool(0,2);','TooltipString','Save graphs','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[65,ymax,20,20],...
'CData',print_dat,'CallBack','plot_proc(19,[]);','TooltipString','Print graphs','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[90,ymax,20,20],...
'CData',edit_dat,'CallBack','legd_proc(3);','TooltipString','Moving Object','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[110,ymax,20,20],...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -