第3个回答 2008-10-07
clear
screen=get(0,'ScreenSize');
W=screen(3);H=screen(4);
%定义菜单选项,绘曲线
figure('Color',[1,1,1],'Position',[0.4*H,0.4*H,0.8*W,0.6*H],'Name',...
'显示函数图形','NumberTitle','off','MenuBar','none');
hplot=uimenu(gcf,'Label','绘曲线');
ss='UIContextMenu';
uimenu(hplot,'Label','sinx/x','Call',['x=0:pi/100:2*pi;y=sin(x)./x;line=plot(x,y);set(line,ss,jhf);']);
uimenu(hplot,'Label','sinx','Call',['x=0:pi/100:2*pi;y=sin(x);line=plot(x,y);set(line,ss,jhf);']);
%定义快捷菜单,实现对图形线型颜色及属性的处理
jhf=uicontextmenu;
xx=uimenu(jhf,'Label','线型');
xk=uimenu(jhf,'Label','线宽');
ys=uimenu(jhf,'Label','颜色');
uimenu(xx,'Label','虚线','Call',['set(line,''LineStyle'','':'');']);
uimenu(xx,'Label','实线','Call',['set(line,''LineStyle'',''-'');']);
uimenu(xx,'Label','点划线','Call',['set(line,''LineStyle'',''-.'');']);
uimenu(xx,'Label','双划线','Call',['set(line,''LineStyle'',''--'');']);
uimenu(xk,'Label','宽','Call',['set(line,''LineWidth'',5);']);
uimenu(xk,'Label','窄','Call',['set(line,''LineWidth'',0.5);']);
uimenu(ys,'Label','蓝色','Call',['set(line,''Color'',''b'');']);
uimenu(ys,'Label','绿色','Call',['set(line,''Color'',''g'');']);
uimenu(ys,'Label','红色','Call',['set(line,''Color'',''r'');']);
uimenu(ys,'Label','青色','Call',['set(line,''LineColor'',''c'');']);
uimenu(ys,'Label','品红色','Call',['set(line,''Color'',''m'');']);
uimenu(ys,'Label','黄色','Call',['set(line,''Color'',''y'');']);
uimenu(ys,'Label','黑色','Call',['set(line,''Color'',''k'');']);
uimenu(ys,'Label','白色','Call',['set(line,''Color'',''w'');']);
set(line,'UIContextMenu',jhf);
%用按钮来实现标记
s='y=sinx/x y=sinx';
jhf1=uicontrol(gcf,'Style','push','Position',[20,20,100,25],'String','显示函数','Callback',['my=max(line);a=find(my);mx=(a+1)*pi/100;text(mx,my,s)']);