matlab建立快捷菜单
发布网友
发布时间:2022-04-23 07:49
我来回答
共3个回答
热心网友
时间:2022-06-17 22:19
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)']);
热心网友
时间:2022-06-17 22:19
我复制你的程序运行了一下,发现你那个问题,但我自己又重新编写了一次,这次是正确的,虽然没有解决你的问题。希望采纳
x=0:pi/100:2*pi;
y=2*exp(-0.5*x).*sin(2*pi*x);
h1=plot(x,y);
hc=uicontextmenu
hls=uimenu(hc,'label','线型');
hlw=uimenu(hc,'label','线宽');
uimenu(hls,'label','虚线','call','set(h1,''linestyle'','':'');');
uimenu(hls,'label','实线','call','set(h1,''linestyle'',''-'');');
uimenu(hlw,'label','加宽','call','set(h1,''linewidth'',5);');
uimenu(hlw,'label','变细','call','set(h1,''linewidth'',1);');
set(h1,'uicontextmenu',hc);
热心网友
时间:2022-06-17 22:20
双引号不要用按shift那个,要一个一个打上去