📄 graf_tool.m
字号:
'CData',text_dat,'CallBack','legd_proc(1,[]);','TooltipString','Draw Text','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[130,ymax,20,20],...
'CData',line_dat,'CallBack','legd_proc(5);','TooltipString','Draw Line','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[150,ymax,20,20],...
'CData',arrow_dat,'CallBack','legd_proc(8);','TooltipString','Draw Arrow','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[175,ymax,20,20],...
'CData',zoom_dat,'CallBack','plot_proc(1,0,0);','TooltipString','Zooming','Tag','Toolz');
uicontrol('Style','PushButton','Units','pixels','Position',[195,ymax,20,20],...
'CData',zoomx_dat,'CallBack','plot_proc(2,0,0);','TooltipString','Zoom X Axis','Tag','Toolz');
uicontrol('Style','PushButton','Units','pixels','Position',[215,ymax,20,20],...
'CData',zoomy_dat,'CallBack','plot_proc(3,0,0);','TooltipString','Zoom Y Axis','Tag','Toolz');
uicontrol('Style','PushButton','Units','pixels','Position',[235,ymax,20,20],...
'CData',fzoom_dat,'CallBack','plot_proc(4,0,0);','TooltipString','Full Axis','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[260,ymax,20,20],...
'CData',cut_dat,'CallBack','plot_proc(20,0);','TooltipString','Delete an Object','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[280,ymax,20,20],...
'CData',color_dat,'CallBack','legd_proc(26,0);','TooltipString','Change Colour','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[300,ymax,20,20],...
'CData',curv_dat,'CallBack','legd_proc(30,0);','TooltipString','Edit Curves','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[320,ymax,20,20],...
'CData',tools_dat,'CallBack','plot_proc(1);','TooltipString','Plot Preferences','Tag','Tools');
uicontrol('Style','ToggleButton','Units','pixels','Position',[340,ymax,20,20],...
'CData',shifty_dat,'CallBack','graf_tool(4,[]);','TooltipString','Shift Axes Down','Tag','Tools');
uicontrol('Style','PushButton','Units','pixels','Position',[375,ymax,20,20],...
'CData',help_dat,'CallBack','clab_help(27);','TooltipString','About Graphics Toolkit','Tag','Tools');
else, set(gcf,'ResizeFcn',''); end
end
%-------------------------------------------------------------------------------------
%chg_graphs is used to change graph properties according to users' own specifications.
%-------------------------------------------------------------------------------------
function chg_graphs(nTask,arg1)
%get all the axis handles under current figure window
g_axes=extra_funs(2); uu=get(gcf,'UserData');
if nargin==1
if nTask~=5, extra_funs(3,uu{1}(2+nTask),'Checked'); end
end
yesno=get(uu{1}(nTask+2),'Checked');
switch nTask
case 1, set(g_axes,'XGrid',yesno,'YGrid',yesno); %set the GRID mode on all the graphics
case 2, set(g_axes,'Box',yesno); %set the BOX mode on all the graphics
case 3, %set the HOLD mode on all the graphics
for i=1:length(g_axes), axes(g_axes(i)); eval(['hold ',yesno]); end
case 4, %set the SQUARE/NORMAL mode on all the graphics
if strcmp(yesno,'on'), axis('square'); else, axis('normal'); end
case 5, delete(g_axes); %clear the current graphics window
end
%-------------------------------------------------------
%graf_file -- administrates the File menu
%-------------------------------------------------------
function g=graf_file(nTask,arg1)
uu=get(gcf,'UserData');
switch nTask
case 1, %Open file and redraw graphs
u_prompt='*.grf';
if length(uu)>=5, u_prompt=[uu{5},u_prompt]; end
[filename,filepath]=uigetfile(u_prompt,'Please Specify the File Name');
if ~isa(filename,'double')
str=[filepath,filename]; uu{3}=str; uu{5}=filepath;
eval(['load(str, ''-mat'');']); set(gcf,'UserData',uu); redraw_plot(Graf_Dat);
end
case 2, %Save current graphs to a file
if nargin==1, Graf_Dat=graf_capture;
else, Graf_Dat=arg1; end
key=0;
if length(uu)>=3,
if length(uu{3})>0, key=1; eval(['save(uu{3},''Graf_Dat'')']); end
end
if key==0, graf_file(3,Graf_Dat); end
case 3, %Save current graphs to a new file
if nargin==1, Graf_Dat=graf_capture;
else, Graf_Dat=arg1; end
u_prompt='*.grf'; uu
if length(uu)>=5, u_prompt=[uu{5},u_prompt]; end
[filename,filepath]=uiputfile(u_prompt,'Please Specify the File Name');
if ~isa(filename,'double')
uu{3}=[filepath,filename]; uu{5}=filepath;
set(gcf,'UserData',uu); graf_file(2,Graf_Dat);
end
end
%-------------------------------------------------------------------------------
%redraw_plot -- from the saved data to draw the plot of a previously saved plot.
%-------------------------------------------------------------------------------
function redraw_plot(g)
delete(extra_funs(2)); %delete all current axes
%find the number of new axes
nCol1=g{1}(1:3); nCol2=g{1}(4:6); nCol3=g{1}(7:9);
set(gcf,'Color',nCol1); [nr,nc]=size(g);
for i=2:nr
%for each of the axes, redraw the plot
pos=g{i}.Pos; h=axes('Position',pos(1:4));
set(h,'XColor',nCol2,'YColor',nCol2,'Color',nCol3,'Xlim',pos(5:6),'Ylim',pos(7:8));
set(h,'Box',g{i}.fBox,'XGrid',g{i}.fXGrid,'YGrid',g{i}.fYGrid,'XScale',g{i}.fX,'YScale',g{i}.fY);
x=g{i}.Dat; [nr0,nc0]=size(x);
for j=1:nc0
if length(x{j})==9, %draw a text
Pos=x{j}{1}; x0=Pos(1); y0=Pos(2);
str=x{j}{2}; nCol=x{j}{3}; vis=x{j}{4}; nFSize=x{j}{5};
fName=x{j}{6}; fWeight=x{j}{7}; fAngle=x{j}{8}; fRot=x{j}{9};
[xL,h]=display_str(x0,y0,str,nCol,vis,nFSize,fName,fWeight,fAngle);
set(h,'Rotation',fRot);
elseif length(x{j})==8, %draw a line
x0=x{j}{1}; y0=x{j}{2}; nCol=x{j}{3}; vis=x{j}{4}; fStyle=x{j}{5};
fMarker=x{j}{6}; fWidth=x{j}{7}; fUserDat=x{j}{8}; h=line(x0,y0);
set(h,'Color',nCol','Visible',vis,'LineStyle',fStyle,'Marker',fMarker,...
'LineWidth',fWidth,'UserData',fUserDat);
end
end
g0=g{i}.XLab; pos=g0{1}; str=g0{2}; hh=xlabel(str); set(hh,'Position',pos);
g0=g{i}.YLab; pos=g0{1}; str=g0{2}; hh=ylabel(str); set(hh,'Position',pos);
g0=g{i}.Lab; pos=g0{1}; str=g0{2}; hh=title(str); set(hh,'Position',pos);
end
%------------------------------------------------------------------------------------
%graf_capture -- extracts the plot elements, axes, line and text only on the existing
%plots. The information will be returned in a variable g using the following syntax
%
% g=graf_capture()
%------------------------------------------------------------------------------------
function g=graf_capture()
g={[get(gcf,'Color'),get(gca,'XColor'),get(gca,'Color')]};
ii=extra_funs(2); %get all the axis handles under current figure window
for i=1:length(ii)
%for each axis handle, capture all the information of the graphics
%elements under it.
%(1) the general properties of the axis
g{i+1,1}=ii(i); h=ii(i); axes(h);
g{i+1}.Pos=[get(h,'Position'),get(h,'XLim'),get(h,'YLim')];
g{i+1}.fBox=get(h,'Box'); g{i+1}.fXGrid=get(h,'XGrid'); g{i+1}.fYGrid=get(h,'YGrid');
g{i+1}.fX=get(h,'XScale'); g{i+1}.fY=get(h,'YScale');
g0=get(gca,'xlabel'); pos=get(g0,'Position'); str=get(g0,'String'); g{i+1}.XLab={pos,str};
g0=get(gca,'ylabel'); pos=get(g0,'Position'); str=get(g0,'String'); g{i+1}.YLab={pos,str};
g0=get(gca,'title'); pos=get(g0,'Position'); str=get(g0,'String'); g{i+1}.Lab={pos,str};
%(2) the general properties of the lines
h_lines=extra_funs(2,'line',1); DD=[]; j=0;
for j=1:length(h_lines)
DD{j}{1}=get(h_lines(j),'XData'); DD{j}{2}=get(h_lines(j),'YData');
DD{j}{3}=get(h_lines(j),'Color'); DD{j}{4}=get(h_lines(j),'Visible');
DD{j}{5}=get(h_lines(j),'LineStyle'); DD{j}{6}=get(h_lines(j),'Marker');
DD{j}{7}=get(h_lines(j),'LineWidth'); DD{j}{8}=get(h_lines(j),'UserData');
end
%(3) the general properties of the text
if length(j)==0, j=0; end; j0=j;
h_texts=extra_funs(2,'text',1);
for j=1:length(h_texts)
DD{j+j0}{1}=get(h_texts(j),'Position'); DD{j+j0}{2}=get(h_texts(j),'String');
DD{j+j0}{3}=get(h_texts(j),'Color'); DD{j+j0}{4}=get(h_texts(j),'Visible');
DD{j+j0}{5}=get(h_texts(j),'FontSize'); DD{j+j0}{6}=get(h_texts(j),'FontName');
DD{j+j0}{7}=get(h_texts(j),'FontWeight'); DD{j+j0}{8}=get(h_texts(j),'FontAngle');
DD{j+j0}{9}=get(h_texts(j),'Rotation');
end
g{i+1}.Dat=DD;
end
%------------------------------------------------------------------------------------
%shifty_plt -- shift the y axis of the plot down or up
%------------------------------------------------------------------------------------
function shifty_plt(key)
drw_dat=graf_capture;
for i=2:length(drw_dat)
pos=drw_dat{i}.Pos; pos(2)=pos(2)-0.04*key; drw_dat{i}.Pos=pos;
end
redraw_plot(drw_dat);
%---------------------------------------------------------------------------
%add_extramenu -- add an extra menu item for simulation analysis, if required.
%---------------------------------------------------------------------------
function h=add_extramenu(nTask,h)
switch nTask
case 1
h(65)=uimenu(h(22),'Label','Add Asymptotics','CallBack','sys_analysis(14);');
case 2,
h(65)=uimenu(h(22),'Label','ATAN Nyquist Plots','CallBack','sys_analysis(15);');
case 5
h(65)=uimenu(h(22),'Label','Add Asymptotics','CallBack','sys_analysis(16);');
case {6,7}
h_main=findobj('Tag','CtrlLABMain');
key=0; uu0=get(h_main,'UserData');
for i=1:3,
g1=get(uu0{1}(i),'UserData');
if length(g1)>0, if g1{1}==4, key=1; break; end, end
end
%check whether nonlinearity/delay is involved in system. If yes, then allow
%simulation parameters specifications
if key==1,
h(65)=uimenu(h(22),'Label','Simulation Parameters','CallBack','sys_analysis;');
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -